blob: b39567b297757bf0d498556a60cf2e5a4750f6d4 [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_JVALUE_H_
18#define ART_RUNTIME_JVALUE_H_
Ian Rogers306057f2012-11-26 12:45:53 -080019
20#include "base/macros.h"
21
Ian Rogers62d6c772013-02-27 08:32:07 -080022#include <stdint.h>
23
Ian Rogers306057f2012-11-26 12:45:53 -080024namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025namespace mirror {
Ian Rogers306057f2012-11-26 12:45:53 -080026class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027} // namespace mirror
Ian Rogers306057f2012-11-26 12:45:53 -080028
29union PACKED(4) JValue {
30 // We default initialize JValue instances to all-zeros.
31 JValue() : j(0) {}
32
33 int8_t GetB() const { return b; }
34 void SetB(int8_t new_b) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -070035 i = ((static_cast<int32_t>(new_b) << 24) >> 24); // Sign-extend.
Ian Rogers306057f2012-11-26 12:45:53 -080036 }
37
38 uint16_t GetC() const { return c; }
39 void SetC(uint16_t new_c) { c = new_c; }
40
41 double GetD() const { return d; }
42 void SetD(double new_d) { d = new_d; }
43
44 float GetF() const { return f; }
45 void SetF(float new_f) { f = new_f; }
46
47 int32_t GetI() const { return i; }
48 void SetI(int32_t new_i) { i = new_i; }
49
50 int64_t GetJ() const { return j; }
51 void SetJ(int64_t new_j) { j = new_j; }
52
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053 mirror::Object* GetL() const { return l; }
54 void SetL(mirror::Object* new_l) { l = new_l; }
Ian Rogers306057f2012-11-26 12:45:53 -080055
56 int16_t GetS() const { return s; }
57 void SetS(int16_t new_s) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -070058 i = ((static_cast<int32_t>(new_s) << 16) >> 16); // Sign-extend.
Ian Rogers306057f2012-11-26 12:45:53 -080059 }
60
61 uint8_t GetZ() const { return z; }
62 void SetZ(uint8_t new_z) { z = new_z; }
63
64 private:
65 uint8_t z;
66 int8_t b;
67 uint16_t c;
68 int16_t s;
69 int32_t i;
70 int64_t j;
71 float f;
72 double d;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073 mirror::Object* l;
Ian Rogers306057f2012-11-26 12:45:53 -080074};
75
76} // namespace art
77
Brian Carlstromfc0e3212013-07-17 14:40:12 -070078#endif // ART_RUNTIME_JVALUE_H_