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 17 #ifndef ART_RUNTIME_JVALUE_H_ 18 #define ART_RUNTIME_JVALUE_H_ 19 20 #include "base/macros.h" 21 #include "base/mutex.h" 22 23 #include <stdint.h> 24 25 #include "obj_ptr.h" 26 27 namespace art { 28 namespace mirror { 29 class Object; 30 } // namespace mirror 31 PACKED(alignof (mirror::Object *))32union PACKED(alignof(mirror::Object*)) JValue { 33 // We default initialize JValue instances to all-zeros. 34 JValue() : j(0) {} 35 36 template<typename T> static JValue FromPrimitive(T v); 37 38 int8_t GetB() const { return b; } 39 void SetB(int8_t new_b) { 40 j = ((static_cast<int64_t>(new_b) << 56) >> 56); // Sign-extend to 64 bits. 41 } 42 43 uint16_t GetC() const { return c; } 44 void SetC(uint16_t new_c) { 45 j = static_cast<int64_t>(new_c); // Zero-extend to 64 bits. 46 } 47 48 double GetD() const { return d; } 49 void SetD(double new_d) { d = new_d; } 50 51 float GetF() const { return f; } 52 void SetF(float new_f) { f = new_f; } 53 54 int32_t GetI() const { return i; } 55 void SetI(int32_t new_i) { 56 j = ((static_cast<int64_t>(new_i) << 32) >> 32); // Sign-extend to 64 bits. 57 } 58 59 int64_t GetJ() const { return j; } 60 void SetJ(int64_t new_j) { j = new_j; } 61 62 mirror::Object* GetL() const REQUIRES_SHARED(Locks::mutator_lock_) { 63 return l; 64 } 65 void SetL(ObjPtr<mirror::Object> new_l) REQUIRES_SHARED(Locks::mutator_lock_); 66 67 int16_t GetS() const { return s; } 68 void SetS(int16_t new_s) { 69 j = ((static_cast<int64_t>(new_s) << 48) >> 48); // Sign-extend to 64 bits. 70 } 71 72 uint8_t GetZ() const { return z; } 73 void SetZ(uint8_t new_z) { 74 j = static_cast<int64_t>(new_z); // Zero-extend to 64 bits. 75 } 76 77 mirror::Object** GetGCRoot() { return &l; } 78 79 private: 80 uint8_t z; 81 int8_t b; 82 uint16_t c; 83 int16_t s; 84 int32_t i; 85 int64_t j; 86 float f; 87 double d; 88 mirror::Object* l; 89 }; 90 91 } // namespace art 92 93 #endif // ART_RUNTIME_JVALUE_H_ 94