MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
jtie_lib.hpp
1 /*
2  Copyright 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 /*
19  * jtie_lib.hpp
20  */
21 
22 #ifndef jtie_lib_hpp
23 #define jtie_lib_hpp
24 
25 #include <jni.h>
26 
27 #include "jtie.hpp"
28 #include "helpers.hpp"
29 
30 // ---------------------------------------------------------------------------
31 // JTie Template Library: Include these global symbol definitions in
32 // exactly one compilation unit
33 // ---------------------------------------------------------------------------
34 
35 // ---------------------------------------------------------------------------
36 // JTie Library: Global Variable Definitions & Template Instantiations
37 // ---------------------------------------------------------------------------
38 
39 JTIE_INSTANTIATE_CLASS_MEMBER_INFO(_ByteBuffer_isReadOnly,
40  "java/nio/ByteBuffer",
41  "isReadOnly",
42  "()Z")
43 
44 JTIE_INSTANTIATE_CLASS_MEMBER_INFO(_ByteBuffer_asReadOnlyBuffer,
45  "java/nio/ByteBuffer",
46  "asReadOnlyBuffer",
47  "()Ljava/nio/ByteBuffer;")
48 
49 JTIE_INSTANTIATE_CLASS_MEMBER_INFO(_ByteBuffer_remaining,
50  "java/nio/ByteBuffer",
51  "remaining",
52  "()I")
53 
54 JTIE_INSTANTIATE_CLASS_MEMBER_INFO(_ByteBuffer_position,
55  "java/nio/ByteBuffer",
56  "position",
57  "()I")
58 
59 JTIE_INSTANTIATE_CLASS_MEMBER_INFO(_Wrapper_cdelegate,
60  "com/mysql/jtie/Wrapper",
61  "cdelegate",
62  "J")
63 
64 // ---------------------------------------------------------------------------
65 // JTie Library: Load and Unload Handlers
66 // ---------------------------------------------------------------------------
67 
68 // root object, which allows Threads to obtain their local JNIEnv
69 static JavaVM * jtie_cached_jvm;
70 
84 jint
85 JTie_OnLoad(JavaVM * jvm, void * reserved)
86 {
87  TRACE("jint JTie_OnLoad(JavaVM *, void *)");
88  (void)reserved;
89  VERBOSE("initializing the JTie resources ...");
90 
91  // beware of circular loading dependencies: do not load classes here
92  // whose static initializers have a dependency upon this native library...
93 
94  // cache the JavaVM pointer
95  jtie_cached_jvm = jvm;
96 
97  // get the JNI environment
98  JNIEnv * env;
99  if (jvm->GetEnv((void**)&env, JNI_VERSION_1_2) != JNI_OK) {
100  return JNI_ERR; // unsupported version or thread not attached to VM
101  }
102 
103  // JTie requires JDK 1.4 JNI functions (e.g., direct ByteBuffer access)
104  VERBOSE("... initialized the JTie resources");
105  return JNI_VERSION_1_4;
106 }
107 
119 void
120 JTie_OnUnload(JavaVM * jvm, void * reserved)
121 {
122  TRACE("void JTie_OnUnload(JavaVM *, void *)");
123  (void)reserved;
124  VERBOSE("releasing the JTie resources ...");
125 
126  // get the JNI environment
127  JNIEnv * env;
128  if (jvm->GetEnv((void**)&env, JNI_VERSION_1_2) != JNI_OK) {
129  return; // unsupported version or thread not attached to VM
130  }
131 
132  jtie_cached_jvm = NULL;
133  VERBOSE("... released the JTie resources");
134 }
135 
136 // ---------------------------------------------------------------------------
137 // JTie Library: Wrapper Class Load Handler
138 // ---------------------------------------------------------------------------
139 
140 #if 0 // XXX not implemented, see comments in Wrapper.java
141 
142 // XXX review & ceanup...
143 
144 // XXX document: cannot cache/store:
145 // JNIEnv -- thread-specific
146 // local references -- call-frame- (and thread-) specific
147 // Local references are valid only inside a single invocation of a native method
148 // Local references are valid only within the thread in which they are created; do not pass between threads
149 // Create a global reference when it is necessary to pass a reference across threads.
150 
151 #include "jtie_Wrapper.h"
152 // XXX how to avoid?
153 //#include "jtie_tconv_idcache_impl.hpp"
154 
155 extern "C" {
156 JNIEXPORT void JNICALL
157 Java_com_mysql_jtie_Wrapper_initIds(JNIEnv *, jclass);
158 
162 JNIEXPORT void JNICALL
163 Java_com_mysql_jtie_Wrapper_initIds(JNIEnv * env, jclass cls)
164 {
165  TRACE("void Java_com_mysql_jtie_Wrapper_initIds(JNIEnv *, jclass)");
166  // store class in a weak global ref to allow for class to be unloaded
167  jtie_cls_com_mysql_jtie_Wrapper = env->NewWeakGlobalRef(cls);
168  if (jtie_cls_com_mysql_jtie_Wrapper == NULL) {
169  return; // OutOfMemoryError pending
170  }
171 }
172 
173 }
174 
175 #endif
176 
177 // ---------------------------------------------------------------------------
178 
179 #endif // jtie_lib_hpp