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