Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 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 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 17 | #include "java_lang_reflect_Proxy.h" |
| 18 | |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 19 | #include "class_linker.h" |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 20 | #include "jni_internal.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | #include "mirror/class_loader.h" |
| 22 | #include "mirror/object_array.h" |
| 23 | #include "mirror/string.h" |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 24 | #include "scoped_fast_native_object_access.h" |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 25 | #include "verify_object-inl.h" |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 29 | static jclass Proxy_generateProxy(JNIEnv* env, jclass, jstring name, jobjectArray interfaces, |
Igor Murashkin | 457e874 | 2015-10-22 17:37:50 -0700 | [diff] [blame] | 30 | jobject loader, jobjectArray methods, jobjectArray throws, |
| 31 | jboolean is_lambda_proxy) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 32 | ScopedFastNativeObjectAccess soa(env); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 33 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Igor Murashkin | 457e874 | 2015-10-22 17:37:50 -0700 | [diff] [blame] | 34 | |
| 35 | mirror::Class* proxy_class = nullptr; |
| 36 | |
| 37 | if (UNLIKELY(is_lambda_proxy)) { |
| 38 | bool already_exists; // XX: Perhaps add lambdaProxyCache to java.lang.ClassLoader ? |
| 39 | proxy_class = class_linker->CreateLambdaProxyClass(soa, |
| 40 | name, |
| 41 | interfaces, |
| 42 | loader, |
| 43 | methods, |
| 44 | throws, |
| 45 | /*out*/&already_exists); |
| 46 | } else { |
| 47 | proxy_class = class_linker->CreateProxyClass(soa, name, interfaces, loader, methods, throws); |
| 48 | } |
| 49 | |
| 50 | return soa.AddLocalReference<jclass>(proxy_class); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 51 | } |
| 52 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 53 | static JNINativeMethod gMethods[] = { |
Igor Murashkin | 457e874 | 2015-10-22 17:37:50 -0700 | [diff] [blame] | 54 | NATIVE_METHOD(Proxy, generateProxy, "!(Ljava/lang/String;[Ljava/lang/Class;Ljava/lang/ClassLoader;[Ljava/lang/reflect/Method;[[Ljava/lang/Class;Z)Ljava/lang/Class;"), |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 55 | }; |
| 56 | |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 57 | void register_java_lang_reflect_Proxy(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 58 | REGISTER_NATIVE_METHODS("java/lang/reflect/Proxy"); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | } // namespace art |