xref: /illumos-gate/usr/src/lib/libdtrace_jni/common/dtj_probe.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <string.h>
28 #include <dtrace_jni.h>
29 
30 /*
31  * This file creates instances of the following Java classes:
32  *	- org.opensolaris.os.dtrace.ProbeDescription
33  *	- org.opensolaris.os.dtrace.ProbeInfo
34  */
35 
36 jobject
dtj_new_probedesc(dtj_java_consumer_t * jc,const dtrace_probedesc_t * probedesc)37 dtj_new_probedesc(dtj_java_consumer_t *jc, const dtrace_probedesc_t *probedesc)
38 {
39 	JNIEnv *jenv = jc->dtjj_jenv;
40 
41 	jstring jprov = NULL;
42 	jstring jmod = NULL;
43 	jstring jfunc = NULL;
44 	jstring jname = NULL;
45 	jobject jprobedesc = NULL;
46 
47 	jprov = (*jenv)->NewStringUTF(jenv, probedesc->dtpd_provider);
48 	if ((*jenv)->ExceptionCheck(jenv)) {
49 		goto cleanup;
50 	}
51 	jmod = (*jenv)->NewStringUTF(jenv, probedesc->dtpd_mod);
52 	if ((*jenv)->ExceptionCheck(jenv)) {
53 		goto cleanup;
54 	}
55 	jfunc = (*jenv)->NewStringUTF(jenv, probedesc->dtpd_func);
56 	if ((*jenv)->ExceptionCheck(jenv)) {
57 		goto cleanup;
58 	}
59 	jname = (*jenv)->NewStringUTF(jenv, probedesc->dtpd_name);
60 	if ((*jenv)->ExceptionCheck(jenv)) {
61 		goto cleanup;
62 	}
63 	jprobedesc = (*jenv)->NewObject(jenv, g_probedesc_jc,
64 	    g_probedescinit_jm, jprov, jmod, jfunc, jname);
65 	if ((*jenv)->ExceptionCheck(jenv)) {
66 		goto cleanup;
67 	}
68 	/* Does not throw exceptions */
69 	(*jenv)->SetIntField(jenv, jprobedesc, g_probedesc_id_jf,
70 	    probedesc->dtpd_id);
71 
72 cleanup:
73 
74 	(*jenv)->DeleteLocalRef(jenv, jprov);
75 	(*jenv)->DeleteLocalRef(jenv, jmod);
76 	(*jenv)->DeleteLocalRef(jenv, jfunc);
77 	(*jenv)->DeleteLocalRef(jenv, jname);
78 	return (jprobedesc);
79 }
80 
81 jobject
dtj_new_probeinfo(dtj_java_consumer_t * jc,const dtrace_probeinfo_t * probeinfo)82 dtj_new_probeinfo(dtj_java_consumer_t *jc, const dtrace_probeinfo_t *probeinfo)
83 {
84 	JNIEnv *jenv = jc->dtjj_jenv;
85 
86 	jobject jprobeattr = NULL;
87 	jobject jargattr = NULL;
88 	jobject jprobeinfo = NULL; /* return value */
89 
90 	jprobeattr = dtj_new_attribute(jc, &probeinfo->dtp_attr);
91 	if ((*jenv)->ExceptionCheck(jenv)) {
92 		return (NULL);
93 	}
94 	jargattr = dtj_new_attribute(jc, &probeinfo->dtp_arga);
95 	if ((*jenv)->ExceptionCheck(jenv)) {
96 		(*jenv)->DeleteLocalRef(jenv, jprobeattr);
97 		return (NULL);
98 	}
99 
100 	jprobeinfo = (*jenv)->NewObject(jenv, g_probeinfo_jc,
101 	    g_probeinfoinit_jm, jprobeattr, jargattr);
102 
103 	(*jenv)->DeleteLocalRef(jenv, jprobeattr);
104 	(*jenv)->DeleteLocalRef(jenv, jargattr);
105 	return (jprobeinfo);
106 }
107