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 
22 #include <stdint.h>
23 
24 namespace art {
25 namespace mirror {
26 class Object;
27 }  // namespace mirror
28 
29 union PACKED(4) JValue {
30   // We default initialize JValue instances to all-zeros.
JValue()31   JValue() : j(0) {}
32 
GetB()33   int8_t GetB() const { return b; }
SetB(int8_t new_b)34   void SetB(int8_t new_b) {
35     i = ((static_cast<int32_t>(new_b) << 24) >> 24);  // Sign-extend.
36   }
37 
GetC()38   uint16_t GetC() const { return c; }
SetC(uint16_t new_c)39   void SetC(uint16_t new_c) { c = new_c; }
40 
GetD()41   double GetD() const { return d; }
SetD(double new_d)42   void SetD(double new_d) { d = new_d; }
43 
GetF()44   float GetF() const { return f; }
SetF(float new_f)45   void SetF(float new_f) { f = new_f; }
46 
GetI()47   int32_t GetI() const { return i; }
SetI(int32_t new_i)48   void SetI(int32_t new_i) { i = new_i; }
49 
GetJ()50   int64_t GetJ() const { return j; }
SetJ(int64_t new_j)51   void SetJ(int64_t new_j) { j = new_j; }
52 
GetL()53   mirror::Object* GetL() const { return l; }
SetL(mirror::Object * new_l)54   void SetL(mirror::Object* new_l) { l = new_l; }
55 
GetS()56   int16_t GetS() const { return s; }
SetS(int16_t new_s)57   void SetS(int16_t new_s) {
58     i = ((static_cast<int32_t>(new_s) << 16) >> 16);  // Sign-extend.
59   }
60 
GetZ()61   uint8_t GetZ() const { return z; }
SetZ(uint8_t new_z)62   void SetZ(uint8_t new_z) { z = new_z; }
63 
GetGCRoot()64   mirror::Object** GetGCRoot() { return &l; }
65 
66  private:
67   uint8_t z;
68   int8_t b;
69   uint16_t c;
70   int16_t s;
71   int32_t i;
72   int64_t j;
73   float f;
74   double d;
75   mirror::Object* l;
76 };
77 
78 }  // namespace art
79 
80 #endif  // ART_RUNTIME_JVALUE_H_
81