Igor Murashkin | 457e874 | 2015-10-22 17:37:50 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | #ifndef ART_RUNTIME_MIRROR_LAMBDA_PROXY_H_ |
| 18 | #define ART_RUNTIME_MIRROR_LAMBDA_PROXY_H_ |
| 19 | |
| 20 | #include "lambda/closure.h" |
| 21 | #include "object.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | struct LambdaProxyOffsets; |
| 26 | |
| 27 | namespace mirror { |
| 28 | |
| 29 | // C++ mirror of a lambda proxy. Does not yet have a Java-equivalent source file. |
| 30 | class MANAGED LambdaProxy FINAL : public Object { |
| 31 | public: |
| 32 | // Note that the runtime subclasses generate the following static fields: |
| 33 | |
| 34 | // private static java.lang.Class[] interfaces; // Declared interfaces for the lambda interface. |
| 35 | static constexpr size_t kStaticFieldIndexInterfaces = 0; |
| 36 | // private static java.lang.Class[][] throws; // Maps vtable id to list of classes. |
| 37 | static constexpr size_t kStaticFieldIndexThrows = 1; |
| 38 | static constexpr size_t kStaticFieldCount = 2; // Number of fields total. |
| 39 | |
| 40 | // The offset from the start of 'LambdaProxy' object, to the closure_ field, in bytes. |
| 41 | // -- This is exposed publically in order to avoid exposing 'closure_' publically. |
| 42 | // -- Only meant to be used in stubs and other compiled code, not in runtime. |
| 43 | static inline MemberOffset GetInstanceFieldOffsetClosure() { |
| 44 | return OFFSET_OF_OBJECT_MEMBER(LambdaProxy, closure_); |
| 45 | } |
| 46 | |
| 47 | // Direct methods available on the class: |
| 48 | static constexpr size_t kDirectMethodIndexConstructor = 0; // <init>()V |
| 49 | static constexpr size_t kDirectMethodCount = 1; // Only the constructor. |
| 50 | |
| 51 | // Accessors to the fields: |
| 52 | |
| 53 | // Get the native closure pointer. Usually non-null outside of lambda proxy contexts. |
| 54 | lambda::Closure* GetClosure() SHARED_REQUIRES(Locks::mutator_lock_) { |
| 55 | return reinterpret_cast<lambda::Closure*>( |
| 56 | GetField64(GetInstanceFieldOffsetClosure())); |
| 57 | } |
| 58 | |
| 59 | // Set the native closure pointer. Usually should be non-null outside of lambda proxy contexts. |
| 60 | void SetClosure(lambda::Closure* closure) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 61 | SetField64<false>(GetInstanceFieldOffsetClosure(), |
| 62 | reinterpret_cast<uint64_t>(closure)); |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | // Instance fields, present in the base class and every generated subclass: |
| 67 | |
| 68 | // private long closure; |
| 69 | union { |
| 70 | lambda::Closure* actual; |
| 71 | uint64_t padding; // Don't trip up GetObjectSize checks, since the Java code has a long. |
| 72 | } closure_; |
| 73 | |
| 74 | // Friends for generating offset tests: |
| 75 | friend struct art::LambdaProxyOffsets; // for verifying offset information |
| 76 | |
| 77 | DISALLOW_IMPLICIT_CONSTRUCTORS(LambdaProxy); |
| 78 | }; |
| 79 | |
| 80 | } // namespace mirror |
| 81 | } // namespace art |
| 82 | |
| 83 | #endif // ART_RUNTIME_MIRROR_LAMBDA_PROXY_H_ |