OSDN Git Service

* Makefile.in: Rebuilt.
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / natRuntime.cc
1 // natRuntime.cc - Implementation of native side of Runtime class.
2
3 /* Copyright (C) 1998, 1999  Cygnus Solutions
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 #include <config.h>
12
13 #include <stdlib.h>
14
15 #include <cni.h>
16 #include <jvm.h>
17 #include <java/lang/Runtime.h>
18 #include <java/lang/UnknownError.h>
19 #include <java/lang/UnsatisfiedLinkError.h>
20
21 #ifdef USE_LTDL
22 #include <ltdl.h>
23 #endif
24
25 void
26 java::lang::Runtime::exit (jint status)
27 {
28   checkExit (status);
29
30   // Make status right for Unix.  This is perhaps strange.
31   if (status < 0 || status > 255)
32     status = 255;
33
34   if (finalize_on_exit)
35     _Jv_RunAllFinalizers ();
36
37   ::exit (status);
38 }
39
40 jlong
41 java::lang::Runtime::freeMemory (void)
42 {
43   return _Jv_GCFreeMemory ();
44 }
45
46 void
47 java::lang::Runtime::gc (void)
48 {
49   _Jv_RunGC ();
50 }
51
52 void
53 java::lang::Runtime::load (jstring path)
54 {
55   JvSynchronize sync (this);
56   checkLink (path);
57   using namespace java::lang;
58 #ifdef USE_LTDL
59   // FIXME: make sure path is absolute.
60   lt_dlhandle h = lt_dlopen (FIXME);
61   if (h == NULL)
62     {
63       const char *msg = lt_dlerror ();
64       _Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg)));
65     }
66 #else
67   _Jv_Throw (new UnknownError
68              (JvNewStringLatin1 ("Runtime.load not implemented")));
69 #endif /* USE_LTDL */
70 }
71
72 void
73 java::lang::Runtime::loadLibrary (jstring lib)
74 {
75   JvSynchronize sync (this);
76   checkLink (lib);
77   using namespace java::lang;
78 #ifdef USE_LTDL
79   // FIXME: make sure path is absolute.
80   lt_dlhandle h = lt_dlopenext (FIXME);
81   if (h == NULL)
82     {
83       const char *msg = lt_dlerror ();
84       _Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg)));
85     }
86 #else
87   _Jv_Throw (new UnknownError
88              (JvNewStringLatin1 ("Runtime.loadLibrary not implemented")));
89 #endif /* USE_LTDL */
90 }
91
92 void
93 java::lang::Runtime::init (void)
94 {
95   finalize_on_exit = false;
96 #ifdef USE_LTDL
97   lt_dlinit ();
98 #endif
99 }
100
101 void
102 java::lang::Runtime::runFinalization (void)
103 {
104   _Jv_RunFinalizers ();
105 }
106
107 jlong
108 java::lang::Runtime::totalMemory (void)
109 {
110   return _Jv_GCTotalMemory ();
111 }
112
113 void
114 java::lang::Runtime::traceInstructions (jboolean)
115 {
116   // Do nothing.
117 }
118
119 void
120 java::lang::Runtime::traceMethodCalls (jboolean)
121 {
122   // Do nothing.
123 }