1 /* 2 * Copyright (c) 2017, 2018, 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 #ifndef SHARE_GC_Z_ZALLOCATIONFLAGS_HPP 25 #define SHARE_GC_Z_ZALLOCATIONFLAGS_HPP 26 27 #include "gc/z/zBitField.hpp" 28 #include "memory/allocation.hpp" 29 30 // 31 // Allocation flags layout 32 // ----------------------- 33 // 34 // 7 3 2 1 0 35 // +----+-+-+-+-+ 36 // |0000|1|1|1|1| 37 // +----+-+-+-+-+ 38 // | | | | | 39 // | | | | * 0-0 Worker Thread Flag (1-bit) 40 // | | | | 41 // | | | * 1-1 Non-Blocking Flag (1-bit) 42 // | | | 43 // | | * 2-2 Relocation Flag (1-bit) 44 // | | 45 // | * 3-3 No Reserve Flag (1-bit) 46 // | 47 // * 7-4 Unused (4-bits) 48 // 49 50 class ZAllocationFlags { 51 private: 52 typedef ZBitField<uint8_t, bool, 0, 1> field_worker_thread; 53 typedef ZBitField<uint8_t, bool, 1, 1> field_non_blocking; 54 typedef ZBitField<uint8_t, bool, 2, 1> field_relocation; 55 typedef ZBitField<uint8_t, bool, 3, 1> field_no_reserve; 56 57 uint8_t _flags; 58 59 public: 60 ZAllocationFlags() : 61 _flags(0) {} 62 63 void set_worker_thread() { 64 _flags |= field_worker_thread::encode(true); 65 } 66 67 void set_non_blocking() { 68 _flags |= field_non_blocking::encode(true); 69 } 70 71 void set_relocation() { 72 _flags |= field_relocation::encode(true); 73 } 74 75 void set_no_reserve() { 76 _flags |= field_no_reserve::encode(true); 77 } 78 79 bool worker_thread() const { 80 return field_worker_thread::decode(_flags); 81 } 82 83 bool non_blocking() const { 84 return field_non_blocking::decode(_flags); 85 } 86 87 bool relocation() const { 88 return field_relocation::decode(_flags); 89 } 90 91 bool no_reserve() const { 92 return field_no_reserve::decode(_flags); 93 } 94 }; 95 96 #endif // SHARE_GC_Z_ZALLOCATIONFLAGS_HPP