xref: /titanic_50/usr/src/lib/libdtrace_jni/common/dtj_probe.c (revision 711890bc9379ceea66272dc8d4981812224ea86e)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <string.h>
30 #include <dtrace_jni.h>
31 
32 /*
33  * This file creates instances of the following Java classes:
34  *	- org.opensolaris.os.dtrace.ProbeDescription
35  *	- org.opensolaris.os.dtrace.ProbeInfo
36  */
37 
38 jobject
39 dtj_new_probedesc(dtj_java_consumer_t *jc, const dtrace_probedesc_t *probedesc)
40 {
41 	JNIEnv *jenv = jc->dtjj_jenv;
42 
43 	jstring jprov = NULL;
44 	jstring jmod = NULL;
45 	jstring jfunc = NULL;
46 	jstring jname = NULL;
47 	jobject jprobedesc = NULL;
48 
49 	jprov = (*jenv)->NewStringUTF(jenv, probedesc->dtpd_provider);
50 	if ((*jenv)->ExceptionCheck(jenv)) {
51 		goto cleanup;
52 	}
53 	jmod = (*jenv)->NewStringUTF(jenv, probedesc->dtpd_mod);
54 	if ((*jenv)->ExceptionCheck(jenv)) {
55 		goto cleanup;
56 	}
57 	jfunc = (*jenv)->NewStringUTF(jenv, probedesc->dtpd_func);
58 	if ((*jenv)->ExceptionCheck(jenv)) {
59 		goto cleanup;
60 	}
61 	jname = (*jenv)->NewStringUTF(jenv, probedesc->dtpd_name);
62 	if ((*jenv)->ExceptionCheck(jenv)) {
63 		goto cleanup;
64 	}
65 	jprobedesc = (*jenv)->NewObject(jenv, g_probedesc_jc,
66 	    g_probedescinit_jm, jprov, jmod, jfunc, jname);
67 	if ((*jenv)->ExceptionCheck(jenv)) {
68 		goto cleanup;
69 	}
70 	/* Does not throw exceptions */
71 	(*jenv)->SetIntField(jenv, jprobedesc, g_probedesc_id_jf,
72 	    probedesc->dtpd_id);
73 
74 cleanup:
75 
76 	(*jenv)->DeleteLocalRef(jenv, jprov);
77 	(*jenv)->DeleteLocalRef(jenv, jmod);
78 	(*jenv)->DeleteLocalRef(jenv, jfunc);
79 	(*jenv)->DeleteLocalRef(jenv, jname);
80 	return (jprobedesc);
81 }
82 
83 jobject
84 dtj_new_probeinfo(dtj_java_consumer_t *jc, const dtrace_probeinfo_t *probeinfo)
85 {
86 	JNIEnv *jenv = jc->dtjj_jenv;
87 
88 	jobject jprobeattr = NULL;
89 	jobject jargattr = NULL;
90 	jobject jprobeinfo = NULL; /* return value */
91 
92 	jprobeattr = dtj_new_attribute(jc, &probeinfo->dtp_attr);
93 	if ((*jenv)->ExceptionCheck(jenv)) {
94 		return (NULL);
95 	}
96 	jargattr = dtj_new_attribute(jc, &probeinfo->dtp_arga);
97 	if ((*jenv)->ExceptionCheck(jenv)) {
98 		(*jenv)->DeleteLocalRef(jenv, jprobeattr);
99 		return (NULL);
100 	}
101 
102 	jprobeinfo = (*jenv)->NewObject(jenv, g_probeinfo_jc,
103 	    g_probeinfoinit_jm, jprobeattr, jargattr);
104 
105 	(*jenv)->DeleteLocalRef(jenv, jprobeattr);
106 	(*jenv)->DeleteLocalRef(jenv, jargattr);
107 	return (jprobeinfo);
108 }
109