CACAO
gnu_classpath_VMSystemProperties.cpp
Go to the documentation of this file.
1 /* src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp
2 
3  Copyright (C) 1996-2014
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #include "vm/types.hpp"
32 
33 #include "mm/memory.hpp"
34 
35 #include "native/jni.hpp"
36 #include "native/native.hpp"
37 
38 #if defined(ENABLE_JNI_HEADERS)
39 # include "native/include/gnu_classpath_VMSystemProperties.h"
40 #endif
41 
42 #include "toolbox/buffer.hpp"
43 
44 #include "vm/exceptions.hpp"
45 #include "vm/properties.hpp"
46 #include "vm/vm.hpp"
47 
48 
49 // Native functions are exported as C functions.
50 extern "C" {
51 
52 /*
53  * Class: gnu/classpath/VMSystemProperties
54  * Method: preInit
55  * Signature: (Ljava/util/Properties;)V
56  */
57 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, jobject properties)
58 {
59  java_handle_t *p;
60 
61  p = (java_handle_t *) properties;
62 
63  if (p == NULL) {
65  return;
66  }
67 
68  // Fill the java.util.Properties object.
70 }
71 
72 
73 /*
74  * Class: gnu/classpath/VMSystemProperties
75  * Method: postInit
76  * Signature: (Ljava/util/Properties;)V
77  */
78 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, jobject properties)
79 {
80  java_handle_t *p;
81 #if defined(ENABLE_JRE_LAYOUT)
82  const char *java_home;
83 #endif
84 
85  p = (java_handle_t *) properties;
86 
87  if (p == NULL) {
89  return;
90  }
91 
92  /* post-set some properties */
93 
94 #if defined(ENABLE_JRE_LAYOUT)
95  /* XXX when we do it that way, we can't set these properties on
96  commandline */
97 
98  java_home = VM::get_current()->get_properties().get("java.home");
99 
100  Properties::put(p, "gnu.classpath.home", java_home);
101 
102  // Use sequence builder to assemble value.
103  Buffer<> buf;
104 
105  buf.write("file://")
106  .write(java_home)
107  .write("/lib");
108 
109  Properties::put(p, "gnu.classpath.home.url", buf.c_str());
110 #endif
111 }
112 
113 } // extern "C"
114 
115 
116 /* native methods implemented by this file ************************************/
117 
118 static JNINativeMethod methods[] = {
119  { (char*) "preInit", (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_preInit },
120  { (char*) "postInit", (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_postInit },
121 };
122 
123 
124 /* _Jv_gnu_classpat_VMSystemProperties_init ************************************
125 
126  Register native functions.
127 
128 *******************************************************************************/
129 
131 {
132  Utf8String u = Utf8String::from_utf8("gnu/classpath/VMSystemProperties");
133 
136 }
137 
138 
139 /*
140  * These are local overrides for various environment variables in Emacs.
141  * Please do not remove this and leave it at the end of the file, where
142  * Emacs will automagically detect them.
143  * ---------------------------------------------------------------------
144  * Local variables:
145  * mode: c++
146  * indent-tabs-mode: t
147  * c-basic-offset: 4
148  * tab-width: 4
149  * End:
150  * vim:noexpandtab:sw=4:ts=4:
151  */
Table containing all native methods registered with the VM.
Definition: native.hpp:132
NativeMethods & get_nativemethods()
Definition: vm.hpp:128
void register_methods(Utf8String classname, const JNINativeMethod *methods, size_t count)
Register native methods with the VM.
Definition: native.cpp:242
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
#define NATIVE_METHODS_COUNT
Definition: native.hpp:45
const char * c_str()
get contents of buffer as zero-terminated c-style-string This strings lifetime is tied to it&#39;s buffer...
Definition: buffer.hpp:489
JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, jobject properties)
void exceptions_throw_nullpointerexception(void)
Properties & get_properties()
Definition: vm.hpp:113
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
void fill(java_handle_t *p)
Fill the given Java system properties with all properties from the internal properties map...
Definition: properties.cpp:611
void _Jv_gnu_classpath_VMSystemProperties_init(void)
Buffer & write(char)
Definition: buffer.hpp:280
static JNINativeMethod methods[]
JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, jobject properties)
static void put(java_handle_t *p, const char *key, const char *value)
Add the given property to the given Java system properties.
Definition: properties.cpp:531
const char * get(const char *key)
Get a property entry from the internal property map.
Definition: properties.cpp:590
static VM * get_current()
Definition: vm.hpp:99