CACAO
gnu_java_lang_VMCPStringBuilder.cpp
Go to the documentation of this file.
1 /* src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp
2 
3  Copyright (C) 2008-2013
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 <stdint.h>
29 
30 #include "native/jni.hpp"
31 #include "native/llni.hpp"
32 #include "native/native.hpp"
33 
34 #if defined(ENABLE_JNI_HEADERS)
35 # include "native/vm/include/gnu_java_lang_VMCPStringBuilder.h"
36 #endif
37 
38 #include "vm/array.hpp"
39 #include "vm/jit/builtin.hpp"
40 #include "vm/exceptions.hpp"
41 #include "vm/globals.hpp"
42 #include "vm/javaobjects.hpp"
43 #include "vm/vm.hpp"
44 
45 /*
46  * Class: gnu/java/lang/VMCPStringBuilder
47  * Method: toString
48  * Signature: ([CII)Ljava/lang/String;
49  */
50 JNIEXPORT jstring JNICALL Java_gnu_java_lang_VMCPStringBuilder_toString(JNIEnv *env, jclass clazz, jcharArray value, jint startIndex, jint count)
51 {
52  /* This is a native version of
53  java.lang.String.<init>([CIIZ)Ljava/lang/String; */
54 
55  if (startIndex < 0) {
56 /* exceptions_throw_stringindexoutofboundsexception("offset: " + offset); */
58  return NULL;
59  }
60 
61  if (count < 0) {
62 /* exceptions_throw_stringindexoutofboundsexception("count: " + count); */
64  return NULL;
65  }
66 
67  /* equivalent to: offset + count < 0 || offset + count > data.length */
68 
69  CharArray ca(value);
70 
71  if (ca.get_length() - startIndex < count) {
72 /* exceptions_throw_stringindexoutofboundsexception("offset + count: " + (offset + count)); */
74  return NULL;
75  }
76 
77  return (jstring) (java_handle_t*) JavaString::from_array(ca.get_handle(), count, startIndex);
78 }
79 
80 
81 /* native methods implemented by this file ************************************/
82 
83 static JNINativeMethod methods[] = {
84  { (char*) "toString", (char*) "([CII)Ljava/lang/String;", (void*) (uintptr_t) &Java_gnu_java_lang_VMCPStringBuilder_toString },
85 };
86 
87 
88 /* _Jv_gnu_java_lang_VMCPStringBuilder *****************************************
89 
90  Register native functions.
91 
92 *******************************************************************************/
93 
95 {
96  Utf8String u = Utf8String::from_utf8("gnu/java/lang/VMCPStringBuilder");
97 
100 }
101 
102 
103 /*
104  * These are local overrides for various environment variables in Emacs.
105  * Please do not remove this and leave it at the end of the file, where
106  * Emacs will automagically detect them.
107  * ---------------------------------------------------------------------
108  * Local variables:
109  * mode: c++
110  * indent-tabs-mode: t
111  * c-basic-offset: 4
112  * tab-width: 4
113  * End:
114  */
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
virtual java_handle_array_t * get_handle() const
Definition: array.hpp:103
static JNINativeMethod methods[]
#define NATIVE_METHODS_COUNT
Definition: native.hpp:45
void _Jv_gnu_java_lang_VMCPStringBuilder_init(void)
static JavaString from_array(java_handle_t *array, int32_t count, int32_t offset)
creates a new java/lang/String with a given char[] WARNING: the char[] is not copied or validated...
Definition: string.cpp:284
int32_t get_length() const
Definition: array.hpp:189
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
JNIEXPORT jstring JNICALL Java_gnu_java_lang_VMCPStringBuilder_toString(JNIEnv *env, jclass clazz, jcharArray value, jint startIndex, jint count)
void exceptions_throw_stringindexoutofboundsexception(void)
static VM * get_current()
Definition: vm.hpp:99