OSDN Git Service

* All files: Updated copyright to reflect Cygnus purchase.
[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, 2000  Red Hat, Inc.
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 <gcj/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
24 /* FIXME: we don't always need this.  The next libtool will let us use
25    AC_LTDL_PREOPEN to see if we do.  */
26 const lt_dlsymlist lt_preloaded_symbols[1] = { { 0, 0 } };
27 #endif
28
29 void
30 java::lang::Runtime::exit (jint status)
31 {
32   checkExit (status);
33
34   // Make status right for Unix.  This is perhaps strange.
35   if (status < 0 || status > 255)
36     status = 255;
37
38   if (finalize_on_exit)
39     _Jv_RunAllFinalizers ();
40
41   ::exit (status);
42 }
43
44 jlong
45 java::lang::Runtime::freeMemory (void)
46 {
47   return _Jv_GCFreeMemory ();
48 }
49
50 void
51 java::lang::Runtime::gc (void)
52 {
53   _Jv_RunGC ();
54 }
55
56 void
57 java::lang::Runtime::load (jstring path)
58 {
59   JvSynchronize sync (this);
60   checkLink (path);
61   using namespace java::lang;
62 #ifdef USE_LTDL
63   jint len = _Jv_GetStringUTFLength (path);
64   char buf[len + 1];
65   jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
66   buf[total] = '\0';
67   // FIXME: make sure path is absolute.
68   lt_dlhandle h = lt_dlopen (buf);
69   if (h == NULL)
70     {
71       const char *msg = lt_dlerror ();
72       _Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg)));
73     }
74 #else
75   _Jv_Throw (new UnknownError
76              (JvNewStringLatin1 ("Runtime.load not implemented")));
77 #endif /* USE_LTDL */
78 }
79
80 void
81 java::lang::Runtime::loadLibrary (jstring lib)
82 {
83   JvSynchronize sync (this);
84   checkLink (lib);
85   using namespace java::lang;
86 #ifdef USE_LTDL
87   jint len = _Jv_GetStringUTFLength (lib);
88   char buf[len + 1];
89   jsize total = JvGetStringUTFRegion (lib, 0, lib->length(), buf);
90   buf[total] = '\0';
91   // FIXME: make sure path is absolute.
92   lt_dlhandle h = lt_dlopenext (buf);
93   if (h == NULL)
94     {
95       const char *msg = lt_dlerror ();
96       _Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg)));
97     }
98 #else
99   _Jv_Throw (new UnknownError
100              (JvNewStringLatin1 ("Runtime.loadLibrary not implemented")));
101 #endif /* USE_LTDL */
102 }
103
104 jboolean
105 java::lang::Runtime::loadLibraryInternal (jstring lib)
106 {
107   JvSynchronize sync (this);
108   using namespace java::lang;
109 #ifdef USE_LTDL
110   jint len = _Jv_GetStringUTFLength (lib);
111   char buf[len + 1];
112   jsize total = JvGetStringUTFRegion (lib, 0, lib->length(), buf);
113   buf[total] = '\0';
114   // FIXME: make sure path is absolute.
115   lt_dlhandle h = lt_dlopenext (buf);
116   return h != NULL;
117 #else
118   return false;
119 #endif /* USE_LTDL */
120 }
121
122 void
123 java::lang::Runtime::init (void)
124 {
125   finalize_on_exit = false;
126 #ifdef USE_LTDL
127   lt_dlinit ();
128 #endif
129 }
130
131 void
132 java::lang::Runtime::runFinalization (void)
133 {
134   _Jv_RunFinalizers ();
135 }
136
137 jlong
138 java::lang::Runtime::totalMemory (void)
139 {
140   return _Jv_GCTotalMemory ();
141 }
142
143 void
144 java::lang::Runtime::traceInstructions (jboolean)
145 {
146   // Do nothing.
147 }
148
149 void
150 java::lang::Runtime::traceMethodCalls (jboolean)
151 {
152   // Do nothing.
153 }