re PR libgcj/16923 (-D* Options passed to JNI_CreateJavaVM are ignored)
[gcc.git] / libjava / gcj / cni.h
1 // gcj/cni.h -*- c++ -*-
2 // This file describes the Compiled Native Interface, CNI.
3 // It provides a nicer interface to many of the things in gcj/javaprims.h.
4
5 /* Copyright (C) 1998, 1999, 2002 Free Software Foundation
6
7 This file is part of libgcj.
8
9 This software is copyrighted work licensed under the terms of the
10 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 details. */
12
13 #ifndef __GCJ_CNI_H__
14 #define __GCJ_CNI_H__
15
16 #include <java/lang/Object.h>
17 #include <java/lang/Class.h>
18
19 #include <gcj/array.h>
20 #include <gcj/javaprims.h>
21
22 #include <string.h>
23
24 extern "C" void _Jv_InitClass (jclass);
25 extern "C" void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
26
27 extern inline void
28 JvInitClass (jclass cls)
29 {
30 return _Jv_InitClass (cls);
31 }
32
33 extern inline void *
34 JvAllocBytes (jsize sz)
35 {
36 return _Jv_AllocBytes (sz);
37 }
38
39 extern inline jstring
40 JvAllocString (jsize sz)
41 {
42 return _Jv_AllocString (sz);
43 }
44
45 extern inline jstring
46 JvNewString (const jchar *chars, jsize len)
47 {
48 return _Jv_NewString (chars, len);
49 }
50
51 extern inline jstring
52 JvNewStringLatin1 (const char *bytes, jsize len)
53 {
54 return _Jv_NewStringLatin1 (bytes, len);
55 }
56
57 extern inline jstring
58 JvNewStringLatin1 (const char *bytes)
59 {
60 return _Jv_NewStringLatin1 (bytes, strlen (bytes));
61 }
62
63 extern inline jchar *
64 _Jv_GetStringChars (jstring str)
65 {
66 return (jchar*)((char*) str->data + str->boffset);
67 }
68
69 extern inline jchar*
70 JvGetStringChars (jstring str)
71 {
72 return _Jv_GetStringChars (str);
73 }
74
75 extern inline jsize
76 JvGetStringUTFLength (jstring string)
77 {
78 return _Jv_GetStringUTFLength (string);
79 }
80
81 extern inline jsize
82 JvGetStringUTFRegion (jstring str, jsize start, jsize len, char *buf)
83 {
84 return _Jv_GetStringUTFRegion (str, start, len, buf);
85 }
86
87 extern inline jstring
88 JvNewStringUTF (const char *bytes)
89 {
90 return _Jv_NewStringUTF (bytes);
91 }
92
93 class JvSynchronize
94 {
95 private:
96 jobject obj;
97 public:
98 JvSynchronize (const jobject &o) : obj (o)
99 { _Jv_MonitorEnter (obj); }
100 ~JvSynchronize ()
101 { _Jv_MonitorExit (obj); }
102 };
103
104 /* Call malloc, but throw exception if insufficient memory. */
105 extern inline void *
106 JvMalloc (jsize size)
107 {
108 return _Jv_Malloc (size);
109 }
110
111 extern inline void
112 JvFree (void *ptr)
113 {
114 return _Jv_Free (ptr);
115 }
116
117 typedef struct _Jv_VMOption JvVMOption;
118 typedef struct _Jv_VMInitArgs JvVMInitArgs;
119
120 extern inline jint
121 JvCreateJavaVM (JvVMInitArgs* vm_args)
122 {
123 return _Jv_CreateJavaVM (vm_args);
124 }
125
126 extern inline java::lang::Thread*
127 JvAttachCurrentThread (jstring name, java::lang::ThreadGroup* group)
128 {
129 return _Jv_AttachCurrentThread (name, group);
130 }
131
132 extern inline java::lang::Thread*
133 JvAttachCurrentThreadAsDaemon (jstring name, java::lang::ThreadGroup* group)
134 {
135 return _Jv_AttachCurrentThreadAsDaemon (name, group);
136 }
137
138 extern inline jint
139 JvDetachCurrentThread (void)
140 {
141 return _Jv_DetachCurrentThread ();
142 }
143 #endif /* __GCJ_CNI_H__ */