Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClearBreakpoint/clrbrk002/clrbrk002.cpp
40951 views
1
/*
2
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
#include <stdio.h>
25
#include <string.h>
26
#include "jvmti.h"
27
#include "agent_common.h"
28
#include "JVMTITools.h"
29
30
extern "C" {
31
32
33
#define PASSED 0
34
#define STATUS_FAILED 2
35
36
static jvmtiEnv *jvmti = NULL;
37
static jvmtiCapabilities caps;
38
static jint result = PASSED;
39
static jboolean printdump = JNI_FALSE;
40
41
#ifdef STATIC_BUILD
42
JNIEXPORT jint JNICALL Agent_OnLoad_clrbrk002(JavaVM *jvm, char *options, void *reserved) {
43
return Agent_Initialize(jvm, options, reserved);
44
}
45
JNIEXPORT jint JNICALL Agent_OnAttach_clrbrk002(JavaVM *jvm, char *options, void *reserved) {
46
return Agent_Initialize(jvm, options, reserved);
47
}
48
JNIEXPORT jint JNI_OnLoad_clrbrk002(JavaVM *jvm, char *options, void *reserved) {
49
return JNI_VERSION_1_8;
50
}
51
#endif
52
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
53
jvmtiError err;
54
jint res;
55
56
if (options != NULL && strcmp(options, "printdump") == 0) {
57
printdump = JNI_TRUE;
58
}
59
60
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
61
if (res != JNI_OK || jvmti == NULL) {
62
printf("Wrong result of a valid call to GetEnv!\n");
63
return JNI_ERR;
64
}
65
66
err = jvmti->GetPotentialCapabilities(&caps);
67
if (err != JVMTI_ERROR_NONE) {
68
printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
69
TranslateError(err), err);
70
return JNI_ERR;
71
}
72
73
err = jvmti->AddCapabilities(&caps);
74
if (err != JVMTI_ERROR_NONE) {
75
printf("(AddCapabilities) unexpected error: %s (%d)\n",
76
TranslateError(err), err);
77
return JNI_ERR;
78
}
79
80
err = jvmti->GetCapabilities(&caps);
81
if (err != JVMTI_ERROR_NONE) {
82
printf("(GetCapabilities) unexpected error: %s (%d)\n",
83
TranslateError(err), err);
84
return JNI_ERR;
85
}
86
87
if (!caps.can_generate_breakpoint_events) {
88
printf("Warning: Breakpoint is not implemented\n");
89
}
90
91
return JNI_OK;
92
}
93
94
JNIEXPORT jint JNICALL
95
Java_nsk_jvmti_ClearBreakpoint_clrbrk002_check(JNIEnv *env, jclass cls) {
96
jvmtiError err;
97
jmethodID mid;
98
jlocation start;
99
jlocation end;
100
101
if (jvmti == NULL) {
102
printf("JVMTI client was not properly loaded!\n");
103
return STATUS_FAILED;
104
}
105
106
if (!caps.can_generate_breakpoint_events) {
107
return result;
108
}
109
110
mid = env->GetStaticMethodID(cls, "run", "([Ljava/lang/String;Ljava/io/PrintStream;)I");
111
if (mid == NULL) {
112
printf("Cannot find method run\n");
113
return STATUS_FAILED;
114
}
115
116
err=jvmti->GetMethodLocation(mid, &start, &end);
117
if (err != JVMTI_ERROR_NONE) {
118
printf("(GetMethodLocation) unexpected error: %s (%d)\n",
119
TranslateError(err), err);
120
return STATUS_FAILED;
121
}
122
123
if (printdump == JNI_TRUE) {
124
printf(">>> location less then starting location check ...\n");
125
}
126
err = jvmti->ClearBreakpoint(mid, start - 1);
127
if (err != JVMTI_ERROR_INVALID_LOCATION) {
128
printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n");
129
printf("\tactual: %s (%d)\n", TranslateError(err), err);
130
result = STATUS_FAILED;
131
}
132
133
if (printdump == JNI_TRUE) {
134
printf(">>> location greater then ending location check ...\n");
135
}
136
err = jvmti->ClearBreakpoint(mid, end + 1);
137
if (err != JVMTI_ERROR_INVALID_LOCATION) {
138
printf("Error expected: JVMTI_ERROR_INVALID_LOCATION,\n");
139
printf("\tactual: %s (%d)\n", TranslateError(err), err);
140
result = STATUS_FAILED;
141
}
142
143
return result;
144
}
145
146
}
147
148