source: trunk/essentials/dev-lang/perl/jpl/JNI/JNI.pm

Last change on this file was 3181, checked in by bird, 18 years ago

perl 5.8.8

File size: 8.4 KB
Line 
1package JNI;
2
3use strict;
4use Carp;
5use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD $JVM @JVM_ARGS $JAVALIB);
6
7require Exporter;
8require DynaLoader;
9require AutoLoader;
10
11@ISA = qw(Exporter DynaLoader);
12
13@EXPORT = qw(
14 JNI_ABORT
15 JNI_COMMIT
16 JNI_ERR
17 JNI_FALSE
18 JNI_H
19 JNI_OK
20 JNI_TRUE
21 GetVersion
22 DefineClass
23 FindClass
24 GetSuperclass
25 IsAssignableFrom
26 Throw
27 ThrowNew
28 ExceptionOccurred
29 ExceptionDescribe
30 ExceptionClear
31 FatalError
32 NewGlobalRef
33 DeleteGlobalRef
34 DeleteLocalRef
35 IsSameObject
36 AllocObject
37 NewObject
38 NewObjectA
39 GetObjectClass
40 IsInstanceOf
41 GetMethodID
42 CallObjectMethod
43 CallObjectMethodA
44 CallBooleanMethod
45 CallBooleanMethodA
46 CallByteMethod
47 CallByteMethodA
48 CallCharMethod
49 CallCharMethodA
50 CallShortMethod
51 CallShortMethodA
52 CallIntMethod
53 CallIntMethodA
54 CallLongMethod
55 CallLongMethodA
56 CallFloatMethod
57 CallFloatMethodA
58 CallDoubleMethod
59 CallDoubleMethodA
60 CallVoidMethod
61 CallVoidMethodA
62 CallNonvirtualObjectMethod
63 CallNonvirtualObjectMethodA
64 CallNonvirtualBooleanMethod
65 CallNonvirtualBooleanMethodA
66 CallNonvirtualByteMethod
67 CallNonvirtualByteMethodA
68 CallNonvirtualCharMethod
69 CallNonvirtualCharMethodA
70 CallNonvirtualShortMethod
71 CallNonvirtualShortMethodA
72 CallNonvirtualIntMethod
73 CallNonvirtualIntMethodA
74 CallNonvirtualLongMethod
75 CallNonvirtualLongMethodA
76 CallNonvirtualFloatMethod
77 CallNonvirtualFloatMethodA
78 CallNonvirtualDoubleMethod
79 CallNonvirtualDoubleMethodA
80 CallNonvirtualVoidMethod
81 CallNonvirtualVoidMethodA
82 GetFieldID
83 GetObjectField
84 GetBooleanField
85 GetByteField
86 GetCharField
87 GetShortField
88 GetIntField
89 GetLongField
90 GetFloatField
91 GetDoubleField
92 SetObjectField
93 SetBooleanField
94 SetByteField
95 SetCharField
96 SetShortField
97 SetIntField
98 SetLongField
99 SetFloatField
100 SetDoubleField
101 GetStaticMethodID
102 CallStaticObjectMethod
103 CallStaticObjectMethodA
104 CallStaticBooleanMethod
105 CallStaticBooleanMethodA
106 CallStaticByteMethod
107 CallStaticByteMethodA
108 CallStaticCharMethod
109 CallStaticCharMethodA
110 CallStaticShortMethod
111 CallStaticShortMethodA
112 CallStaticIntMethod
113 CallStaticIntMethodA
114 CallStaticLongMethod
115 CallStaticLongMethodA
116 CallStaticFloatMethod
117 CallStaticFloatMethodA
118 CallStaticDoubleMethod
119 CallStaticDoubleMethodA
120 CallStaticVoidMethod
121 CallStaticVoidMethodA
122 GetStaticFieldID
123 GetStaticObjectField
124 GetStaticBooleanField
125 GetStaticByteField
126 GetStaticCharField
127 GetStaticShortField
128 GetStaticIntField
129 GetStaticLongField
130 GetStaticFloatField
131 GetStaticDoubleField
132 SetStaticObjectField
133 SetStaticBooleanField
134 SetStaticByteField
135 SetStaticCharField
136 SetStaticShortField
137 SetStaticIntField
138 SetStaticLongField
139 SetStaticFloatField
140 SetStaticDoubleField
141 NewString
142 GetStringLength
143 GetStringChars
144 NewStringUTF
145 GetStringUTFLength
146 GetStringUTFChars
147 GetArrayLength
148 NewObjectArray
149 GetObjectArrayElement
150 SetObjectArrayElement
151 NewBooleanArray
152 NewByteArray
153 NewCharArray
154 NewShortArray
155 NewIntArray
156 NewLongArray
157 NewFloatArray
158 NewDoubleArray
159 GetBooleanArrayElements
160 GetByteArrayElements
161 GetCharArrayElements
162 GetShortArrayElements
163 GetIntArrayElements
164 GetLongArrayElements
165 GetFloatArrayElements
166 GetDoubleArrayElements
167 GetBooleanArrayRegion
168 GetByteArrayRegion
169 GetCharArrayRegion
170 GetShortArrayRegion
171 GetIntArrayRegion
172 GetLongArrayRegion
173 GetFloatArrayRegion
174 GetDoubleArrayRegion
175 SetBooleanArrayRegion
176 SetByteArrayRegion
177 SetCharArrayRegion
178 SetShortArrayRegion
179 SetIntArrayRegion
180 SetLongArrayRegion
181 SetFloatArrayRegion
182 SetDoubleArrayRegion
183 RegisterNatives
184 UnregisterNatives
185 MonitorEnter
186 MonitorExit
187 GetJavaVM
188);
189
190$VERSION = '0.2';
191
192sub AUTOLOAD {
193 # This AUTOLOAD is used to 'autoload' constants from the constant()
194 # XS function. If a constant is not found then control is passed
195 # to the AUTOLOAD in AutoLoader.
196
197 my $constname;
198 ($constname = $AUTOLOAD) =~ s/.*:://;
199 my $val = constant($constname, @_ ? $_[0] : 0);
200 if ($! != 0) {
201 if ($! =~ /Invalid/) {
202 $AutoLoader::AUTOLOAD = $AUTOLOAD;
203 goto &AutoLoader::AUTOLOAD;
204 }
205 else {
206 croak "Your vendor has not defined JNI macro $constname";
207 }
208 }
209 eval "sub $AUTOLOAD { $val }";
210 goto &$AUTOLOAD;
211}
212
213bootstrap JNI $VERSION;
214
215if (not $JPL::_env_) {
216 # Note that only Kaffe support only cares about what JNI::Config says
217 use JNI::Config qw($KAFFE $LD_LIBRARY_PATH $CLASS_HOME $LIB_HOME $JAVA_LIB);
218
219 # Win32 and Sun JDK pay attention to $ENV{JAVA_HOME}; Kaffe doesn't
220 $ENV{JAVA_HOME} ||= "/usr/local/java";
221
222 my ($arch, @CLASSPATH);
223 if ($^O eq 'MSWin32' and (! $JNI::Config::KAFFE) ) {
224
225 $arch = 'MSWin32' unless -d "$ENV{JAVA_HOME}/lib/$arch";
226 @CLASSPATH = split(/;/, $ENV{CLASSPATH});
227 @CLASSPATH = "." unless @CLASSPATH;
228 push @CLASSPATH,
229 "$ENV{JAVA_HOME}\\classes",
230 "$ENV{JAVA_HOME}\\lib\\classes.zip",
231 # MSR - added for JDK 1.3
232 "$ENV{JAVA_HOME}\\jre\\lib\\rt.jar",
233 # MSR - added to find Closer.class
234 '.';
235
236 $ENV{CLASSPATH} = join(';', @CLASSPATH);
237 $ENV{THREADS_TYPE} ||= "green_threads";
238
239 #$JAVALIB = "$ENV{JAVA_HOME}/lib/$arch/$ENV{THREADS_TYPE}";
240 # MSR - changed above for JDK 1.3
241 $JAVALIB = "$ENV{JAVA_HOME}/lib/";
242
243 $ENV{LD_LIBRARY_PATH} .= ":$JAVALIB";
244
245 push @JVM_ARGS, "classpath", $ENV{CLASSPATH};
246 print "JVM_ARGS=@JVM_ARGS!\n" if $JPL::DEBUG;
247 $JVM = GetJavaVM("$JAVALIB/javai.dll",@JVM_ARGS);
248 } elsif ($^O eq 'MSWin32' and $JNI::Config::KAFFE) {
249 croak "Kaffe is not yet supported on MSWin32 platform!";
250 } elsif ($JNI::Config::KAFFE) {
251 # The following code has to build a classpath for us. It would be
252 # better if we could have *both* a classpath and a classhome, and
253 # not have to "guess" at the classpath like this. We should be able
254 # to send in, say, a classpath of ".", and classhome of
255 # ".../share/kaffe", and have it build the right classpath. That
256 # doesn't work. The function initClasspath() in findInJar.c in the
257 # Kaffe source says: "Oh, you have a classpath, well forget
258 # classhome!" This seems brain-dead to me. But, anyway, that's why
259 # I don't use the classhome option on GetJavaVM. I have to build
260 # the classpath by hand. *sigh*
261 # -- bkuhn
262
263 my $classpath = $ENV{CLASSPATH} || ".";
264 my %classCheck;
265 @classCheck{split(/\s*:\s*/, $classpath)} = 1;
266 foreach my $jarFile (qw(Klasses.jar comm.jar pjava.jar
267 tools.jar microsoft.jar rmi.jar)) {
268 $classpath .= ":$JNI::Config::CLASS_HOME/$jarFile"
269 unless defined $classCheck{"$JNI::Config::CLASS_HOME/$jarFile"};
270 # Assume that if someone else already put these here, they knew
271 # what they were doing and have the order right.
272 }
273 $classpath = ".:$classpath" unless defined $classCheck{"."};
274
275 $ENV{CLASSPATH} = $classpath; # Not needed for GetJavaVM(), since
276 # we pass it in as a JVM option, but
277 # something else might expect it.
278 # (also see comment above)
279 print STDERR "bkuhn: JNI classpath=$classpath\n";
280 unshift(@JVM_ARGS, "classpath", $classpath,
281 "libraryhome", $JNI::Config::LIB_HOME);
282
283 # The following line is useless; see comment above.
284 # "classhome", $JNI::Config::CLASS_HOME);
285
286 $JVM = GetJavaVM($JNI::Config::JAVA_LIB, @JVM_ARGS);
287 } else {
288 chop($arch = `uname -p`);
289 chop($arch = `uname -m`) unless -d "$ENV{JAVA_HOME}/lib/$arch";
290
291 @CLASSPATH = split(/:/, $ENV{CLASSPATH});
292 @CLASSPATH = "." unless @CLASSPATH;
293 push @CLASSPATH,
294 "$ENV{JAVA_HOME}/classes",
295 "$ENV{JAVA_HOME}/lib/classes.zip";
296 $ENV{CLASSPATH} = join(':', @CLASSPATH);
297
298 $ENV{THREADS_TYPE} ||= "green_threads";
299
300 $JAVALIB = "$ENV{JAVA_HOME}/lib/$arch/$ENV{THREADS_TYPE}";
301 $ENV{LD_LIBRARY_PATH} .= ":$JAVALIB";
302 push @JVM_ARGS, "classpath", $ENV{CLASSPATH};
303 print "JVM_ARGS=@JVM_ARGS!\n" if $JPL::DEBUG;
304 $JVM = GetJavaVM("$JAVALIB/libjava.so",@JVM_ARGS);
305 }
306}
307
3081;
309__END__
310
311=head1 NAME
312
313JNI - Perl encapsulation of the Java Native Interface
314
315=head1 SYNOPSIS
316
317 use JNI;
318
319=head1 DESCRIPTION
320
321=head1 Exported constants
322
323 JNI_ABORT
324 JNI_COMMIT
325 JNI_ERR
326 JNI_FALSE
327 JNI_H
328 JNI_OK
329 JNI_TRUE
330
331
332=head1 AUTHOR
333
334Copyright 1998, O'Reilly & Associates, Inc.
335
336This package may be copied under the same terms as Perl itself.
337
338=head1 SEE ALSO
339
340perl(1).
341
342=cut
Note: See TracBrowser for help on using the repository browser.