blob: fa85937dcd4d2279f979e5e3edab7326cbac99a9 [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 {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023namespace mirror {
Ian Rogers306057f2012-11-26 12:45:53 -080024class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025} // namespace mirror
Ian Rogers306057f2012-11-26 12:45:53 -080026
27union PACKED(4) JValue {
28 // We default initialize JValue instances to all-zeros.
29 JValue() : j(0) {}
30
31 int8_t GetB() const { return b; }
32 void SetB(int8_t new_b) {
33 i = ((static_cast<int32_t>(new_b) << 24) >> 24); // Sign-extend.
34 }
35
36 uint16_t GetC() const { return c; }
37 void SetC(uint16_t new_c) { c = new_c; }
38
39 double GetD() const { return d; }
40 void SetD(double new_d) { d = new_d; }
41
42 float GetF() const { return f; }
43 void SetF(float new_f) { f = new_f; }
44
45 int32_t GetI() const { return i; }
46 void SetI(int32_t new_i) { i = new_i; }
47
48 int64_t GetJ() const { return j; }
49 void SetJ(int64_t new_j) { j = new_j; }
50
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080051 mirror::Object* GetL() const { return l; }
52 void SetL(mirror::Object* new_l) { l = new_l; }
Ian Rogers306057f2012-11-26 12:45:53 -080053
54 int16_t GetS() const { return s; }
55 void SetS(int16_t new_s) {
56 i = ((static_cast<int32_t>(new_s) << 16) >> 16); // Sign-extend.
57 }
58
59 uint8_t GetZ() const { return z; }
60 void SetZ(uint8_t new_z) { z = new_z; }
61
62 private:
63 uint8_t z;
64 int8_t b;
65 uint16_t c;
66 int16_t s;
67 int32_t i;
68 int64_t j;
69 float f;
70 double d;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071 mirror::Object* l;
Ian Rogers306057f2012-11-26 12:45:53 -080072};
73
74} // namespace art
75
76#endif // ART_SRC_JVALUE_H_