blob: f61a07c0c0234d5fe67daa5f16f347d8aa086d82 [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"
Mathieu Chartier28bd2e42016-10-04 13:54:57 -070021#include "base/mutex.h"
Ian Rogers306057f2012-11-26 12:45:53 -080022
Ian Rogers62d6c772013-02-27 08:32:07 -080023#include <stdint.h>
24
Mathieu Chartier28bd2e42016-10-04 13:54:57 -070025#include "obj_ptr.h"
26
Ian Rogers306057f2012-11-26 12:45:53 -080027namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028namespace mirror {
Ian Rogers306057f2012-11-26 12:45:53 -080029class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030} // namespace mirror
Ian Rogers306057f2012-11-26 12:45:53 -080031
Mathieu Chartierb12be8c2016-12-01 14:54:38 -080032union PACKED(alignof(mirror::Object*)) JValue {
Ian Rogers306057f2012-11-26 12:45:53 -080033 // We default initialize JValue instances to all-zeros.
34 JValue() : j(0) {}
35
36 int8_t GetB() const { return b; }
37 void SetB(int8_t new_b) {
Douglas Leung44f10192015-09-23 16:42:08 -070038 j = ((static_cast<int64_t>(new_b) << 56) >> 56); // Sign-extend to 64 bits.
Ian Rogers306057f2012-11-26 12:45:53 -080039 }
40
41 uint16_t GetC() const { return c; }
buzbeee667a3c2017-03-09 13:51:23 -080042 void SetC(uint16_t new_c) {
43 j = static_cast<int64_t>(new_c); // Zero-extend to 64 bits.
44 }
Ian Rogers306057f2012-11-26 12:45:53 -080045
46 double GetD() const { return d; }
47 void SetD(double new_d) { d = new_d; }
48
49 float GetF() const { return f; }
50 void SetF(float new_f) { f = new_f; }
51
52 int32_t GetI() const { return i; }
Douglas Leung44f10192015-09-23 16:42:08 -070053 void SetI(int32_t new_i) {
54 j = ((static_cast<int64_t>(new_i) << 32) >> 32); // Sign-extend to 64 bits.
55 }
Ian Rogers306057f2012-11-26 12:45:53 -080056
57 int64_t GetJ() const { return j; }
58 void SetJ(int64_t new_j) { j = new_j; }
59
Mathieu Chartier28bd2e42016-10-04 13:54:57 -070060 mirror::Object* GetL() const REQUIRES_SHARED(Locks::mutator_lock_) {
61 return l;
62 }
63 void SetL(ObjPtr<mirror::Object> new_l) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -080064
65 int16_t GetS() const { return s; }
66 void SetS(int16_t new_s) {
Douglas Leung44f10192015-09-23 16:42:08 -070067 j = ((static_cast<int64_t>(new_s) << 48) >> 48); // Sign-extend to 64 bits.
Ian Rogers306057f2012-11-26 12:45:53 -080068 }
69
70 uint8_t GetZ() const { return z; }
buzbeee667a3c2017-03-09 13:51:23 -080071 void SetZ(uint8_t new_z) {
72 j = static_cast<int64_t>(new_z); // Zero-extend to 64 bits.
73 }
Ian Rogers306057f2012-11-26 12:45:53 -080074
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -070075 mirror::Object** GetGCRoot() { return &l; }
76
Ian Rogers306057f2012-11-26 12:45:53 -080077 private:
78 uint8_t z;
79 int8_t b;
80 uint16_t c;
81 int16_t s;
82 int32_t i;
83 int64_t j;
84 float f;
85 double d;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086 mirror::Object* l;
Ian Rogers306057f2012-11-26 12:45:53 -080087};
88
89} // namespace art
90
Brian Carlstromfc0e3212013-07-17 14:40:12 -070091#endif // ART_RUNTIME_JVALUE_H_