java_lang_String.cc revision 4e30541a92381fb280cd0be9a1763b713ee4d64c
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "common_throws.h"
18#include "jni_internal.h"
19#include "mirror/string.h"
20#include "scoped_fast_native_object_access.h"
21#include "scoped_thread_state_change.h"
22#include "ScopedLocalRef.h"
23#include "verify_object-inl.h"
24
25namespace art {
26
27static jint String_compareTo(JNIEnv* env, jobject javaThis, jobject javaRhs) {
28  ScopedFastNativeObjectAccess soa(env);
29  if (UNLIKELY(javaRhs == NULL)) {
30    ThrowNullPointerException(NULL, "rhs == null");
31    return -1;
32  } else {
33    return soa.Decode<mirror::String*>(javaThis)->CompareTo(soa.Decode<mirror::String*>(javaRhs));
34  }
35}
36
37static jint String_fastIndexOf(JNIEnv* env, jobject java_this, jint ch, jint start) {
38  ScopedFastNativeObjectAccess soa(env);
39  // This method does not handle supplementary characters. They're dealt with in managed code.
40  DCHECK_LE(ch, 0xffff);
41
42  mirror::String* s = soa.Decode<mirror::String*>(java_this);
43  return s->FastIndexOf(ch, start);
44}
45
46static jstring String_intern(JNIEnv* env, jobject javaThis) {
47  ScopedFastNativeObjectAccess soa(env);
48  mirror::String* s = soa.Decode<mirror::String*>(javaThis);
49  mirror::String* result = s->Intern();
50  return soa.AddLocalReference<jstring>(result);
51}
52
53static JNINativeMethod gMethods[] = {
54  NATIVE_METHOD(String, compareTo, "!(Ljava/lang/String;)I"),
55  NATIVE_METHOD(String, fastIndexOf, "!(II)I"),
56  NATIVE_METHOD(String, intern, "!()Ljava/lang/String;"),
57};
58
59void register_java_lang_String(JNIEnv* env) {
60  REGISTER_NATIVE_METHODS("java/lang/String");
61}
62
63}  // namespace art
64