1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_OOPS_ARRAYSTORAGEPROPERTIES_HPP 26 #define SHARE_OOPS_ARRAYSTORAGEPROPERTIES_HPP 27 28 #include "runtime/globals.hpp" 29 30 class ArrayStorageProperties { 31 private: 32 uint8_t _flags; 33 34 void clear_flags_bits(uint8_t value) { _flags &= (~value); } 35 void set_flags_bits(uint8_t value) { _flags |= value; } 36 bool test_flags_bit(int idx) const { return (_flags & (1 << idx)) != 0; } 37 public: 38 39 enum { 40 empty_value = 0, 41 flattened_bit = 0, 42 flattened_value = 1 << flattened_bit, 43 null_free_bit = flattened_bit + 1, 44 null_free_value = 1 << null_free_bit, 45 nof_oop_properties = null_free_bit + 1, 46 }; 47 48 ArrayStorageProperties() : _flags(empty_value) {}; 49 ArrayStorageProperties(uint8_t flags): _flags(flags) {}; 50 51 bool is_empty() const { return _flags == empty_value; } 52 53 void clear_flattened() { clear_flags_bits(flattened_value); } 54 55 bool is_flattened() const { return test_flags_bit(flattened_bit); } 56 void set_flattened() { set_flags_bits(flattened_value); } 57 58 bool is_null_free() const { return test_flags_bit(null_free_bit); } 59 void set_null_free() { set_flags_bits(null_free_value); } 60 61 uint8_t value() const { return _flags; } 62 template <typename T> T encode(int shift) const { return static_cast<T>(_flags) << shift; } 63 64 // Well-known constants... 65 static const ArrayStorageProperties empty; 66 static const ArrayStorageProperties flattened; 67 static const ArrayStorageProperties null_free; 68 static const ArrayStorageProperties flattened_and_null_free; 69 }; 70 71 72 #endif //SHARE_OOPS_ARRAYSTORAGEPROPERTIES_HPP