CUBRID Engine  latest
jsp_sr.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * jsp_sr.c - Java Stored Procedure Server Module Source
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #if defined(WINDOWS)
28 #include <windows.h>
29 #define DELAYIMP_INSECURE_WRITABLE_HOOKS
30 #include <Delayimp.h>
31 #pragma comment(lib, "delayimp")
32 #pragma comment(lib, "jvm")
33 #else /* WINDOWS */
34 #include <dlfcn.h>
35 #endif /* !WINDOWS */
36 
37 #include <jni.h>
38 #include <locale.h>
39 #include <assert.h>
40 #include <vector>
41 #include <string>
42 #include <sstream>
43 #include <iterator>
44 
45 #include "jsp_sr.h"
46 #include "jsp_file.h"
47 
48 #include "boot_sr.h"
49 #include "environment_variable.h"
50 #include "system_parameter.h"
51 #include "release_string.h"
52 #include "memory_alloc.h"
53 #include "error_manager.h"
54 
55 #if defined(sparc)
56 #define JVM_LIB_PATH "jre/lib/sparc/client"
57 #define JVM_LIB_PATH_JDK11 "lib/server"
58 #elif defined(WINDOWS)
59 #if __WORDSIZE == 32
60 #define JVM_LIB_PATH_JDK "jre\\bin\\client"
61 #define JVM_LIB_PATH_JRE "bin\\client"
62 #define JVM_LIB_PATH_JDK11 "" /* JDK 11 does not support for Windows x64 */
63 #else
64 #define JVM_LIB_PATH_JDK "jre\\bin\\server"
65 #define JVM_LIB_PATH_JRE "bin\\server"
66 #define JVM_LIB_PATH_JDK11 "bin\\server"
67 #endif
68 #elif defined(HPUX) && defined(IA64)
69 #define JVM_LIB_PATH "jre/lib/IA64N/hotspot"
70 #define JVM_LIB_PATH_JDK11 "lib/IA64N/server"
71 #elif defined(HPUX) && !defined(IA64)
72 #define JVM_LIB_PATH "jre/lib/PA_RISC2.0/hotspot"
73 #define JVM_LIB_PATH_JDK11 "lib/PA_RISC2.0/server"
74 #elif defined(AIX)
75 #if __WORDSIZE == 32
76 #define JVM_LIB_PATH "jre/bin/classic"
77 #define JVM_LIB_PATH_JDK11 "lib/server"
78 #elif __WORDSIZE == 64
79 #define JVM_LIB_PATH "jre/lib/ppc64/classic"
80 #define JVM_LIB_PATH_JDK11 "lib/server"
81 #endif
82 #elif defined(__i386) || defined(__x86_64)
83 #if __WORDSIZE == 32
84 #define JVM_LIB_PATH "jre/lib/i386/client"
85 #define JVM_LIB_PATH_JDK11 "lib/server"
86 #else
87 #define JVM_LIB_PATH "jre/lib/amd64/server"
88 #define JVM_LIB_PATH_JDK11 "lib/server"
89 #endif
90 #else /* ETC */
91 #define JVM_LIB_PATH ""
92 #define JVM_LIB_PATH_JDK11 ""
93 #endif /* ETC */
94 
95 #if !defined(WINDOWS)
96 #if defined(AIX)
97 #define JVM_LIB_FILE "libjvm.so"
98 #elif defined(HPUX) && !defined(IA64)
99 #define JVM_LIB_FILE "libjvm.sl"
100 #else /* not AIX , not ( HPUX && (not IA64)) */
101 #define JVM_LIB_FILE "libjvm.so"
102 #endif /* not AIX , not ( HPUX && (not IA64)) */
103 #endif /* !WINDOWS */
104 
105 #if defined(WINDOWS)
106 #define REGKEY_JAVA "Software\\JavaSoft\\Java Runtime Environment"
107 #endif /* WINDOWS */
108 
109 #define BUF_SIZE 2048
110 typedef jint (*CREATE_VM_FUNC) (JavaVM **, void **, void *);
111 
112 #ifdef __cplusplus
113 #define JVM_GetEnv(JVM, ENV, VER) \
114  (JVM)->GetEnv(ENV, VER)
115 #define JVM_AttachCurrentThread(JVM, ENV, ARGS) \
116  (JVM)->AttachCurrentThread(ENV, ARGS)
117 #define JVM_DetachCurrentThread(JVM) \
118  (JVM)->DetachCurrentThread()
119 #define JVM_ExceptionOccurred(ENV) \
120  (ENV)->ExceptionOccurred()
121 #define JVM_FindClass(ENV, NAME) \
122  (ENV)->FindClass(NAME)
123 #define JVM_GetStaticMethodID(ENV, CLAZZ, NAME, SIG) \
124  (ENV)->GetStaticMethodID(CLAZZ, NAME, SIG)
125 #define JVM_NewStringUTF(ENV, BYTES) \
126  (ENV)->NewStringUTF(BYTES);
127 #define JVM_NewObjectArray(ENV, LENGTH, ELEMENTCLASS, INITIALCLASS) \
128  (ENV)->NewObjectArray(LENGTH, ELEMENTCLASS, INITIALCLASS)
129 #define JVM_SetObjectArrayElement(ENV, ARRAY, INDEX, VALUE) \
130  (ENV)->SetObjectArrayElement(ARRAY, INDEX, VALUE)
131 #define JVM_CallStaticVoidMethod(ENV, CLAZZ, METHODID, ARGS) \
132  (ENV)->CallStaticVoidMethod(CLAZZ, METHODID, ARGS)
133 #define JVM_CallStaticIntMethod(ENV, CLAZZ, METHODID, ARGS) \
134  (ENV)->CallStaticIntMethod(CLAZZ, METHODID, ARGS)
135 #define JVM_CallStaticObjectMethod(ENV, CLAZZ, METHODID, ARGS) \
136  (ENV)->CallStaticObjectMethod(CLAZZ, METHODID, ARGS)
137 #define JVM_GetStringUTF(ENV, STRING) \
138  (ENV)->GetStringUTFChars(STRING, NULL)
139 #define JVM_ReleaseStringUTF(ENV, JSTRING, CSTRING) \
140  (ENV)->ReleaseStringUTFChars(JSTRING, CSTRING)
141 #define JVM_GetStringUTFLength(ENV, STRING) \
142  (ENV)->GetStringUTFLength(STRING)
143 #else
144 #define JVM_GetEnv(JVM, ENV, VER) \
145  (*JVM)->GetEnv(JVM, ENV, VER)
146 #define JVM_AttachCurrentThread(JVM, ENV, ARGS) \
147  (*JVM)->AttachCurrentThread(JVM, ENV, ARGS)
148 #define JVM_DetachCurrentThread(JVM) \
149  (*JVM)->DetachCurrentThread(JVM)
150 #define JVM_ExceptionOccurred(ENV) \
151  (*ENV)->ExceptionOccurred(ENV)
152 #define JVM_FindClass(ENV, NAME) \
153  (*ENV)->FindClass(ENV, NAME)
154 #define JVM_GetStaticMethodID(ENV, CLAZZ, NAME, SIG) \
155  (*ENV)->GetStaticMethodID(ENV, CLAZZ, NAME, SIG)
156 #define JVM_NewStringUTF(ENV, BYTES) \
157  (*ENV)->NewStringUTF(ENV, BYTES);
158 #define JVM_NewObjectArray(ENV, LENGTH, ELEMENTCLASS, INITIALCLASS) \
159  (*ENV)->NewObjectArray(ENV, LENGTH, ELEMENTCLASS, INITIALCLASS)
160 #define JVM_SetObjectArrayElement(ENV, ARRAY, INDEX, VALUE) \
161  (*ENV)->SetObjectArrayElement(ENV, ARRAY, INDEX, VALUE)
162 #define JVM_CallStaticVoidMethod(ENV, CLAZZ, METHODID, ARGS) \
163  (*ENV)->CallStaticVoidMethod(ENV, CLAZZ, METHODID, ARGS)
164 #define JVM_CallStaticIntMethod(ENV, CLAZZ, METHODID, ARGS) \
165  (*ENV)->CallStaticIntMethod(ENV, CLAZZ, METHODID, ARGS)
166 #define JVM_CallStaticObjectMethod(ENV, CLAZZ, METHODID, ARGS) \
167  (*ENV)->CallStaticObjectMethod(ENV, CLAZZ, METHODID, ARGS)
168 #define JVM_GetStringUTF(ENV, STRING) \
169  (*ENV)->GetStringUTFChars(ENV, STRING, NULL)
170 #define JVM_ReleaseStringUTF(ENV, JSTRING, CSTRING) \
171  (*ENV)->ReleaseStringUTFChars(ENV, JSTRING, CSTRING)
172 #define JVM_GetStringUTFLength(ENV, STRING) \
173  (*ENV)->GetStringUTFLength(ENV, STRING)
174 #endif
175 
176 static JavaVM *jvm = NULL;
177 static jint sp_port = -1;
178 // *INDENT-OFF*
179 static std::string err_msgs;
180 // *INDENT-ON*
181 
182 #if defined(WINDOWS)
183 int get_java_root_path (char *path);
184 FARPROC WINAPI delay_load_hook (unsigned dliNotify, PDelayLoadInfo pdli);
185 LONG WINAPI delay_load_dll_exception_filter (PEXCEPTION_POINTERS pep);
186 
187 extern PfnDliHook __pfnDliNotifyHook2 = delay_load_hook;
188 extern PfnDliHook __pfnDliFailureHook2 = delay_load_hook;
189 
190 #else /* WINDOWS */
191 static void *jsp_get_create_java_vm_function_ptr (void);
192 #endif /* !WINDOWS */
193 
194 #if defined(WINDOWS)
195 
196 /*
197  * get_java_root_path()
198  * return: return FALSE on error othrewise true
199  * path(in/out): get java root path
200  *
201  * Note:
202  */
203 
204 int
205 get_java_root_path (char *path)
206 {
207  DWORD rc;
208  DWORD len;
209  DWORD dwType;
210  char currentVersion[16];
211  char regkey_java_current_version[BUF_SIZE];
212  char java_root_path[BUF_SIZE];
213  HKEY hKeyReg;
214 
215  if (!path)
216  {
217  return false;
218  }
219 
220  rc = RegOpenKeyEx (HKEY_LOCAL_MACHINE, REGKEY_JAVA, 0, KEY_QUERY_VALUE, &hKeyReg);
221  if (rc != ERROR_SUCCESS)
222  {
223  return false;
224  }
225 
226  len = sizeof (currentVersion);
227  rc = RegQueryValueEx (hKeyReg, "CurrentVersion", 0, &dwType, (LPBYTE) currentVersion, &len);
228 
229  if (hKeyReg)
230  {
231  RegCloseKey (hKeyReg);
232  }
233 
234  if (rc != ERROR_SUCCESS)
235  {
236  return false;
237  }
238 
239  hKeyReg = NULL;
240  sprintf (regkey_java_current_version, "%s\\%s", REGKEY_JAVA, currentVersion);
241  rc = RegOpenKeyEx (HKEY_LOCAL_MACHINE, regkey_java_current_version, 0, KEY_QUERY_VALUE, &hKeyReg);
242 
243  if (rc != ERROR_SUCCESS)
244  {
245  return false;
246  }
247 
248  len = sizeof (java_root_path);
249  rc = RegQueryValueEx (hKeyReg, "JavaHome", 0, &dwType, (LPBYTE) java_root_path, &len);
250 
251  if (hKeyReg)
252  {
253  RegCloseKey (hKeyReg);
254  }
255 
256  if (rc != ERROR_SUCCESS)
257  {
258  return false;
259  }
260 
261  strcpy (path, java_root_path);
262  return true;
263 }
264 
265 /*
266  * delay_load_hook -
267  * return:
268  * dliNotify(in):
269  * pdli(in):
270  *
271  * Note:
272  */
273 
274 FARPROC WINAPI
275 delay_load_hook (unsigned dliNotify, PDelayLoadInfo pdli)
276 {
277  FARPROC fp = NULL;
278 
279  switch (dliNotify)
280  {
281  case dliFailLoadLib:
282  {
283  char *java_home = NULL, *jvm_path = NULL, *tmp = NULL, *tail;
284  void *libVM = NULL;
285 
286  jvm_path = getenv ("JVM_PATH");
287  java_home = getenv ("JAVA_HOME");
288 
289  if (jvm_path)
290  {
291  err_msgs.append ("\n\tFailed to load libjvm from 'JVM_PATH' envirnment variable: ");
292  err_msgs.append ("\n\t\t");
293  err_msgs.append (jvm_path);
294 
295  libVM = LoadLibrary (jvm_path);
296  if (libVM)
297  {
298  fp = (FARPROC) (HMODULE) libVM;
299  return fp;
300  }
301  }
302  else
303  {
304  err_msgs.append ("\n\tFailed to get 'JVM_PATH' environment variable");
305  }
306 
307  tail = JVM_LIB_PATH_JDK;
308  if (java_home == NULL)
309  {
310  tmp = (char *) malloc (BUF_SIZE);
311  if (tmp)
312  {
313  if (get_java_root_path (tmp))
314  {
315  java_home = tmp;
316  tail = JVM_LIB_PATH_JRE;
317  }
318  }
319  }
320 
321  if (java_home)
322  {
323  err_msgs.append ("\n\tFailed to load libjvm from 'JAVA_HOME' environment variable: ");
324 
325  char jvm_lib_path[BUF_SIZE];
326  sprintf (jvm_lib_path, "%s\\%s\\jvm.dll", java_home, tail);
327 
328  err_msgs.append ("\n\t\t");
329  err_msgs.append (jvm_lib_path);
330 
331  libVM = LoadLibrary (jvm_lib_path);
332 
333  if (libVM)
334  {
335  fp = (FARPROC) (HMODULE) libVM;
336  }
337  else
338  {
339  tail = JVM_LIB_PATH_JDK11;
340 
341  memset (jvm_lib_path, BUF_SIZE, 0);
342  sprintf (jvm_lib_path, "%s\\%s\\jvm.dll", java_home, tail);
343 
344  err_msgs.append ("\n\t\t");
345  err_msgs.append (jvm_lib_path);
346 
347  libVM = LoadLibrary (jvm_lib_path);
348  fp = (FARPROC) (HMODULE) libVM;
349  }
350  }
351  else
352  {
353  err_msgs.append ("\n\tFailed to get 'JAVA_HOME' environment variable");
354  }
355 
356  if (tmp)
357  {
358  free_and_init (tmp);
359  }
360  }
361  break;
362 
363  default:
364  break;
365  }
366 
367  return fp;
368 }
369 
370 /*
371  * delay_load_dll_exception_filter -
372  * return:
373  * pep(in):
374  *
375  * Note:
376  */
377 
378 LONG WINAPI
379 delay_load_dll_exception_filter (PEXCEPTION_POINTERS pep)
380 {
381  switch (pep->ExceptionRecord->ExceptionCode)
382  {
383  case VcppException (ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND):
384  case VcppException (ERROR_SEVERITY_ERROR, ERROR_PROC_NOT_FOUND):
386  break;
387 
388  default:
389  break;
390  }
391 
392  return EXCEPTION_EXECUTE_HANDLER;
393 }
394 
395 #else /* WINDOWS */
396 
397 /*
398  * jsp_get_create_java_vm_func_ptr
399  * return: return java vm function pointer
400  *
401  * Note:
402  */
403 
404 static void *
406 {
407  void *libVM_p = NULL;
408 
409  char *jvm_path = getenv ("JVM_PATH");
410  if (jvm_path != NULL)
411  {
412  libVM_p = dlopen (jvm_path, RTLD_NOW | RTLD_LOCAL);
413  if (libVM_p != NULL)
414  {
415  return dlsym (libVM_p, "JNI_CreateJavaVM");
416  }
417  else
418  {
419  err_msgs.append ("\n\tFailed to load libjvm from 'JVM_PATH' environment variable: ");
420  err_msgs.append ("\n\t\t");
421  err_msgs.append (dlerror ());
422  }
423  }
424  else
425  {
426  err_msgs.append ("\n\tFailed to get 'JVM_PATH' environment variable");
427  }
428 
429  char *java_home = getenv ("JAVA_HOME");
430  if (java_home != NULL)
431  {
432  char jvm_library_path[PATH_MAX];
433  err_msgs.append ("\n\tFailed to load libjvm from 'JAVA_HOME' environment variable: ");
434 
435  // under jdk 11
436  snprintf (jvm_library_path, PATH_MAX - 1, "%s/%s/%s", java_home, JVM_LIB_PATH, JVM_LIB_FILE);
437  libVM_p = dlopen (jvm_library_path, RTLD_NOW | RTLD_LOCAL);
438  if (libVM_p != NULL)
439  {
440  return dlsym (libVM_p, "JNI_CreateJavaVM");
441  }
442  else
443  {
444  err_msgs.append ("\n\t\t");
445  err_msgs.append (dlerror ());
446  }
447 
448  // from jdk 11
449  snprintf (jvm_library_path, PATH_MAX - 1, "%s/%s/%s", java_home, JVM_LIB_PATH_JDK11, JVM_LIB_FILE);
450  libVM_p = dlopen (jvm_library_path, RTLD_NOW | RTLD_LOCAL);
451  if (libVM_p != NULL)
452  {
453  return dlsym (libVM_p, "JNI_CreateJavaVM");
454  }
455  else
456  {
457  err_msgs.append ("\n\t\t");
458  err_msgs.append (dlerror ());
459  }
460  }
461  else
462  {
463  err_msgs.append ("\n\tFailed to get 'JAVA_HOME' environment variable");
464  }
465 
466  return NULL;
467 }
468 
469 #endif /* !WINDOWS */
470 
471 
472 /*
473  * jsp_create_java_vm
474  * return: create java vm
475  *
476  * Note:
477  */
478 static int
479 jsp_create_java_vm (JNIEnv ** env_p, JavaVMInitArgs * vm_arguments)
480 {
481  int res;
482 #if defined(WINDOWS)
483  __try
484  {
485  res = JNI_CreateJavaVM (&jvm, (void **) env_p, vm_arguments);
486  }
487  __except (delay_load_dll_exception_filter (GetExceptionInformation ()))
488  {
489  res = -1;
490  }
491 #else /* WINDOWS */
493  if (create_vm_func)
494  {
495  res = (*create_vm_func) (&jvm, (void **) env_p, (void *) vm_arguments);
496  }
497  else
498  {
500  res = -1;
501  }
502 #endif /* WINDOWS */
503  err_msgs.clear ();
504  return res;
505 }
506 
507 /*
508  * jsp_tokenize_jvm_options
509  * return: tokenized array of string
510  *
511  */
512 
513 // *INDENT-OFF*
514 static std::vector <std::string>
516 {
517  std::string str (opt_str);
518  std::istringstream iss (str);
519  std::vector <std::string> options;
520  std::copy (std::istream_iterator <std::string> (iss),
521  std::istream_iterator <std::string> (), std::back_inserter (options));
522  return options;
523 }
524 // *INDENT-ON*
525 
526 /*
527  * jsp_start_server -
528  * return: Error Code
529  * db_name(in): db name
530  * path(in): path
531  *
532  * Note:
533  */
534 
535 int
536 jsp_start_server (const char *db_name, const char *path, int port)
537 {
538  jint res;
539  jclass cls, string_cls;
540  JNIEnv *env_p = NULL;
541  jmethodID mid;
542  jstring jstr_dbname, jstr_path, jstr_version, jstr_envroot, jstr_port;
543  jobjectArray args;
544  JavaVMInitArgs vm_arguments;
545  JavaVMOption *options;
546  int vm_n_options = 3;
547  char classpath[PATH_MAX + 32] = { 0 };
548  char logging_prop[PATH_MAX + 32] = { 0 };
549  char option_debug[70];
550  char debug_flag[] = "-Xdebug";
551  char debug_jdwp[] = "-agentlib:jdwp=transport=dt_socket,server=y,address=%d,suspend=n";
552  char disable_sig_handle[] = "-Xrs";
553  const char *envroot;
554  char jsp_file_path[PATH_MAX];
555  char port_str[6] = { 0 };
556  char *loc_p, *locale;
557  char *jvm_opt_sysprm = NULL;
558  int debug_port = -1;
559  {
560  if (jvm != NULL)
561  {
562  return ER_SP_ALREADY_EXIST; /* already created */
563  }
564 
565  envroot = envvar_root ();
566 
567  snprintf (classpath, sizeof (classpath) - 1, "-Djava.class.path=%s",
568  envvar_javadir_file (jsp_file_path, PATH_MAX, "jspserver.jar"));
569 
570  snprintf (logging_prop, sizeof (logging_prop) - 1, "-Djava.util.logging.config.file=%s",
571  envvar_javadir_file (jsp_file_path, PATH_MAX, "logging.properties"));
572 
574  if (debug_port != -1)
575  {
576  vm_n_options += 2; /* set debug flag and debugging port */
577  }
578 
580  // *INDENT-OFF*
581  std::vector <std::string> opts = jsp_tokenize_jvm_options (jvm_opt_sysprm);
582  // *INDENT-ON*
583  vm_n_options += (int) opts.size ();
584  options = new JavaVMOption[vm_n_options];
585  if (options == NULL)
586  {
588  goto error;
589  }
590 
591  int idx = 3;
592  options[0].optionString = classpath;
593  options[1].optionString = logging_prop;
594  options[2].optionString = disable_sig_handle;
595  if (debug_port != -1)
596  {
597  idx += 2;
598  snprintf (option_debug, sizeof (option_debug) - 1, debug_jdwp, debug_port);
599  options[3].optionString = debug_flag;
600  options[4].optionString = option_debug;
601  }
602 
603  for (auto it = opts.begin (); it != opts.end (); ++it)
604  {
605  // *INDENT-OFF*
606  options[idx++].optionString = const_cast <char*> (it->c_str ());
607  // *INDENT-ON*
608  }
609 
610  vm_arguments.version = JNI_VERSION_1_6;
611  vm_arguments.nOptions = vm_n_options;
612  vm_arguments.options = options;
613  vm_arguments.ignoreUnrecognized = JNI_TRUE;
614 
615  locale = NULL;
616  loc_p = setlocale (LC_TIME, NULL);
617  if (loc_p != NULL)
618  {
619  locale = strdup (loc_p);
620  }
621 
622  res = jsp_create_java_vm (&env_p, &vm_arguments);
623  // *INDENT-OFF*
624  delete[] options;
625  // *INDENT-ON*
626 
627 #if !defined(WINDOWS)
628  if (er_has_error ())
629  {
630  if (locale != NULL)
631  {
632  free (locale);
633  }
634  return er_errid ();
635  }
636 #endif
637 
638  setlocale (LC_TIME, locale);
639  if (locale != NULL)
640  {
641  free (locale);
642  }
643 
644  if (res < 0)
645  {
646  jvm = NULL;
647  return er_errid ();
648  }
649 
650  cls = JVM_FindClass (env_p, "com/cubrid/jsp/Server");
651  if (cls == NULL)
652  {
653  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM, 1, "FindClass: " "com/cubrid/jsp/Server");
654  goto error;
655  }
656 
657  mid = JVM_GetStaticMethodID (env_p, cls, "main", "([Ljava/lang/String;)V");
658  if (mid == NULL)
659  {
661  "GetStaticMethodID: " "com/cubrid/jsp/Server.main([Ljava/lang/String;)V");
662  goto error;
663  }
664 
665  jstr_dbname = JVM_NewStringUTF (env_p, db_name);
666  if (jstr_dbname == NULL)
667  {
669  "Failed to construct a new 'java.lang.String object' by NewStringUTF()");
670  goto error;
671  }
672 
673  jstr_path = JVM_NewStringUTF (env_p, path);
674  if (jstr_path == NULL)
675  {
677  "Failed to construct a new 'java.lang.String object' by NewStringUTF()");
678  goto error;
679  }
680 
681  jstr_version = JVM_NewStringUTF (env_p, rel_build_number ());
682  if (jstr_version == NULL)
683  {
685  "Failed to construct a new 'java.lang.String object' by NewStringUTF()");
686  goto error;
687  }
688 
689  jstr_envroot = JVM_NewStringUTF (env_p, envroot);
690  if (jstr_envroot == NULL)
691  {
693  "Failed to construct a new 'java.lang.String object' by NewStringUTF()");
694  goto error;
695  }
696 
697  sprintf (port_str, "%d", port);
698  jstr_port = JVM_NewStringUTF (env_p, port_str);
699  if (jstr_port == NULL)
700  {
702  "Failed to construct a new 'java.lang.String object' by NewStringUTF()");
703  goto error;
704  }
705 
706  string_cls = JVM_FindClass (env_p, "java/lang/String");
707  if (string_cls == NULL)
708  {
709  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM, 1, "FindClass: " "java/lang/String");
710  goto error;
711  }
712 
713  args = JVM_NewObjectArray (env_p, 5, string_cls, NULL);
714  if (args == NULL)
715  {
717  "Failed to construct a new java array by NewObjectArray()");
718  goto error;
719  }
720 
721  JVM_SetObjectArrayElement (env_p, args, 0, jstr_dbname);
722  JVM_SetObjectArrayElement (env_p, args, 1, jstr_path);
723  JVM_SetObjectArrayElement (env_p, args, 2, jstr_version);
724  JVM_SetObjectArrayElement (env_p, args, 3, jstr_envroot);
725  JVM_SetObjectArrayElement (env_p, args, 4, jstr_port);
726 
727  sp_port = JVM_CallStaticIntMethod (env_p, cls, mid, args);
728  if (JVM_ExceptionOccurred (env_p) || sp_port == -1)
729  {
731  "Error occured while starting Java SP Server by CallStaticIntMethod()");
732  goto error;
733  }
734 
735  return NO_ERROR;
736  }
737 error:
738  assert (er_errid () != NO_ERROR);
739  return er_errid ();
740 }
741 
742 /*
743  * jsp_server_port
744  * return: if disable jsp function and return -1
745  * enable jsp function and return jsp server port
746  *
747  * Note:
748  */
749 
750 int
752 {
753 #if defined (SA_MODE)
754  return sp_port;
755 #else
756  // check $CUBRID/var/javasp_<db_name>.info
757 // *INDENT-OFF*
758  JAVASP_SERVER_INFO jsp_info {-1, -1};
759 // *INDENT-ON*
760  javasp_read_info (boot_db_name (), jsp_info);
761  return jsp_info.port;
762 #endif
763 }
764 
765 /*
766  * jsp_jvm_is_loaded
767  * return: if disable jsp function and return false
768  * enable jsp function and return not false
769  *
770  * Note:
771  */
772 
773 int
775 {
776  return jvm != NULL;
777 }
#define JVM_LIB_FILE
Definition: jsp_sr.c:101
const char * envvar_root(void)
#define ER_SP_ALREADY_EXIST
Definition: error_code.h:1105
static JavaVM * jvm
Definition: jsp_sr.c:176
#define NO_ERROR
Definition: error_code.h:46
int debug_flag
Definition: unloaddb.c:56
#define JVM_ExceptionOccurred(ENV)
Definition: jsp_sr.c:150
#define JVM_LIB_PATH_JDK11
Definition: jsp_sr.c:92
const char * boot_db_name(void)
Definition: boot_sr.c:459
#define JVM_SetObjectArrayElement(ENV, ARRAY, INDEX, VALUE)
Definition: jsp_sr.c:160
#define JVM_LIB_PATH
Definition: jsp_sr.c:91
char * envvar_javadir_file(char *path, size_t size, const char *filename)
#define JVM_NewStringUTF(ENV, BYTES)
Definition: jsp_sr.c:156
int jsp_jvm_is_loaded(void)
Definition: jsp_sr.c:774
int er_errid(void)
bool javasp_read_info(const char *db_name, JAVASP_SERVER_INFO &info)
Definition: jsp_file.c:132
const char * rel_build_number(void)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int jsp_start_server(const char *db_name, const char *path, int port)
Definition: jsp_sr.c:536
#define assert(x)
int prm_get_integer_value(PARAM_ID prm_id)
#define ER_SP_CANNOT_START_JVM
Definition: error_code.h:1126
#define ER_OUT_OF_VIRTUAL_MEMORY
Definition: error_code.h:50
static std::vector< std::string > jsp_tokenize_jvm_options(char *opt_str)
Definition: jsp_sr.c:515
#define JVM_CallStaticIntMethod(ENV, CLAZZ, METHODID, ARGS)
Definition: jsp_sr.c:164
#define JVM_FindClass(ENV, NAME)
Definition: jsp_sr.c:152
static std::string err_msgs
Definition: jsp_sr.c:179
#define NULL
Definition: freelistheap.h:34
#define JVM_GetStaticMethodID(ENV, CLAZZ, NAME, SIG)
Definition: jsp_sr.c:154
static int jsp_create_java_vm(JNIEnv **env_p, JavaVMInitArgs *vm_arguments)
Definition: jsp_sr.c:479
#define BUF_SIZE
Definition: jsp_sr.c:109
char * db_name
static void error(const char *msg)
Definition: gencat.c:331
static int rc
Definition: serial.c:50
#define ARG_FILE_LINE
Definition: error_manager.h:44
bool er_has_error(void)
#define free_and_init(ptr)
Definition: memory_alloc.h:147
char * prm_get_string_value(PARAM_ID prm_id)
static void * jsp_get_create_java_vm_function_ptr(void)
Definition: jsp_sr.c:405
#define ER_SP_JVM_LIB_NOT_FOUND
Definition: error_code.h:1125
int jsp_server_port(void)
Definition: jsp_sr.c:751
static jint sp_port
Definition: jsp_sr.c:177
char * strdup(const char *str)
Definition: porting.c:901
#define JVM_NewObjectArray(ENV, LENGTH, ELEMENTCLASS, INITIALCLASS)
Definition: jsp_sr.c:158
jint(* CREATE_VM_FUNC)(JavaVM **, void **, void *)
Definition: jsp_sr.c:110