• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     j = ((static_cast<int64_t>(new_b) << 56) >> 56);  // Sign-extend to 64 bits.
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) {
49     j = ((static_cast<int64_t>(new_i) << 32) >> 32);  // Sign-extend to 64 bits.
50   }
51 
GetJ()52   int64_t GetJ() const { return j; }
SetJ(int64_t new_j)53   void SetJ(int64_t new_j) { j = new_j; }
54 
GetL()55   mirror::Object* GetL() const { return l; }
SetL(mirror::Object * new_l)56   void SetL(mirror::Object* new_l) { l = new_l; }
57 
GetS()58   int16_t GetS() const { return s; }
SetS(int16_t new_s)59   void SetS(int16_t new_s) {
60     j = ((static_cast<int64_t>(new_s) << 48) >> 48);  // Sign-extend to 64 bits.
61   }
62 
GetZ()63   uint8_t GetZ() const { return z; }
SetZ(uint8_t new_z)64   void SetZ(uint8_t new_z) { z = new_z; }
65 
GetGCRoot()66   mirror::Object** GetGCRoot() { return &l; }
67 
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;
77   mirror::Object* l;
78 };
79 
80 }  // namespace art
81 
82 #endif  // ART_RUNTIME_JVALUE_H_
83