Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_JVALUE_H_ |
| 18 | #define ART_RUNTIME_JVALUE_H_ |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 19 | |
| 20 | #include "base/macros.h" |
| 21 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 24 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | namespace mirror { |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 26 | class Object; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | } // namespace mirror |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 28 | |
| 29 | union PACKED(4) JValue { |
| 30 | // We default initialize JValue instances to all-zeros. |
| 31 | JValue() : j(0) {} |
| 32 | |
| 33 | int8_t GetB() const { return b; } |
| 34 | void SetB(int8_t new_b) { |
Douglas Leung | 44f1019 | 2015-09-23 16:42:08 -0700 | [diff] [blame] | 35 | j = ((static_cast<int64_t>(new_b) << 56) >> 56); // Sign-extend to 64 bits. |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | uint16_t GetC() const { return c; } |
| 39 | void SetC(uint16_t new_c) { c = new_c; } |
| 40 | |
| 41 | double GetD() const { return d; } |
| 42 | void SetD(double new_d) { d = new_d; } |
| 43 | |
| 44 | float GetF() const { return f; } |
| 45 | void SetF(float new_f) { f = new_f; } |
| 46 | |
| 47 | int32_t GetI() const { return i; } |
Douglas Leung | 44f1019 | 2015-09-23 16:42:08 -0700 | [diff] [blame] | 48 | void SetI(int32_t new_i) { |
| 49 | j = ((static_cast<int64_t>(new_i) << 32) >> 32); // Sign-extend to 64 bits. |
| 50 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 51 | |
| 52 | int64_t GetJ() const { return j; } |
| 53 | void SetJ(int64_t new_j) { j = new_j; } |
| 54 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 55 | mirror::Object* GetL() const { return l; } |
| 56 | void SetL(mirror::Object* new_l) { l = new_l; } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 57 | |
| 58 | int16_t GetS() const { return s; } |
| 59 | void SetS(int16_t new_s) { |
Douglas Leung | 44f1019 | 2015-09-23 16:42:08 -0700 | [diff] [blame] | 60 | j = ((static_cast<int64_t>(new_s) << 48) >> 48); // Sign-extend to 64 bits. |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | uint8_t GetZ() const { return z; } |
| 64 | void SetZ(uint8_t new_z) { z = new_z; } |
| 65 | |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 66 | mirror::Object** GetGCRoot() { return &l; } |
| 67 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 68 | private: |
| 69 | uint8_t z; |
| 70 | int8_t b; |
| 71 | uint16_t c; |
| 72 | int16_t s; |
| 73 | int32_t i; |
| 74 | int64_t j; |
| 75 | float f; |
| 76 | double d; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 77 | mirror::Object* l; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace art |
| 81 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 82 | #endif // ART_RUNTIME_JVALUE_H_ |