mod.rs 3.63 KB
Newer Older
1
// Copyright 2017 The Australian National University
qinsoon's avatar
qinsoon committed
2
//
3 4 5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
qinsoon's avatar
qinsoon committed
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
qinsoon's avatar
qinsoon committed
8
//
9 10 11 12 13 14
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

qinsoon's avatar
qinsoon committed
15
use utils::*;
qinsoon's avatar
qinsoon committed
16
use heap::*;
17

18 19 20 21
mod immix_space;
mod immix_mutator;

pub use self::immix_space::ImmixSpace;
22 23
pub use self::immix_space::ImmixBlock;
pub use self::immix_mutator::ImmixAllocator;
24 25
pub use self::immix_mutator::CURSOR_OFFSET;
pub use self::immix_mutator::LIMIT_OFFSET;
26

27 28 29
pub use self::immix_space::mark_object_traced;
pub use self::immix_space::is_object_traced;

qinsoon's avatar
qinsoon committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
// Immix space
// |------------------| <- 16GB align
// | metadata         |
// | ...              | (64 KB)
// |------------------|
// | block mark table | (256 KB) - 256K blocks, 1 byte per block
// |------------------|
// | line mark table  | (64MB) - 64M lines, 1 byte per line
// |------------------|
// | gc byte table    | (1GB) - 1/16 of memory, 1 byte per 16 (min alignment/object size)
// |------------------|
// | type byte table  | (1GB) - 1/16 of memory, 1 byte per 16 (min alignment/object size)
// |------------------|
// | memory starts    |
// | ......           |
// | ......           |
// |__________________|



// 64KB Immix Block
pub const LOG_BYTES_IN_BLOCK: usize = 16;
pub const BYTES_IN_BLOCK: ByteSize = 1 << LOG_BYTES_IN_BLOCK;

// 256B Immix line
qinsoon's avatar
qinsoon committed
55
pub const LOG_BYTES_IN_LINE: usize = 8;
56 57
pub const BYTES_IN_LINE: ByteSize = (1 << LOG_BYTES_IN_LINE);

qinsoon's avatar
qinsoon committed
58
// 256K blocks per space
qinsoon's avatar
qinsoon committed
59
pub const BLOCKS_IN_SPACE: usize = 1 << (LOG_BYTES_PREALLOC_SPACE - LOG_BYTES_IN_BLOCK);
qinsoon's avatar
qinsoon committed
60
// 64M lines per space
qinsoon's avatar
qinsoon committed
61
pub const LINES_IN_SPACE: usize = 1 << (LOG_BYTES_PREALLOC_SPACE - LOG_BYTES_IN_LINE);
qinsoon's avatar
qinsoon committed
62
// 2G words per space
qinsoon's avatar
qinsoon committed
63
pub const WORDS_IN_SPACE: usize = 1 << (LOG_BYTES_PREALLOC_SPACE - LOG_POINTER_SIZE);
qinsoon's avatar
qinsoon committed
64 65
// 256 lines per block
pub const LINES_IN_BLOCK: usize = 1 << (LOG_BYTES_IN_BLOCK - LOG_BYTES_IN_LINE);
qinsoon's avatar
qinsoon committed
66
pub const LOG_LINES_IN_BLOCK: usize = LOG_BYTES_IN_BLOCK - LOG_BYTES_IN_LINE;
67

qinsoon's avatar
qinsoon committed
68
// 64KB space metadata (we do not need this much though, but for alignment, we use 64KB)
qinsoon's avatar
qinsoon committed
69
pub const BYTES_META_SPACE: ByteSize = BYTES_IN_BLOCK;
qinsoon's avatar
qinsoon committed
70 71 72 73 74 75 76
// 256KB block mark table (1 byte per block)
pub const BYTES_META_BLOCK_MARK_TABLE: ByteSize = BLOCKS_IN_SPACE;
// 64MB line mark table
pub const BYTES_META_LINE_MARK_TABLE: ByteSize = LINES_IN_SPACE;
// 1GB GC byte table
pub const BYTES_META_GC_TABLE: ByteSize = WORDS_IN_SPACE >> 1;
// 1GB TYPE byte table
qinsoon's avatar
qinsoon committed
77
pub const BYTES_META_TYPE_TABLE: ByteSize = WORDS_IN_SPACE >> 1;
78

qinsoon's avatar
qinsoon committed
79 80 81 82 83 84
pub const OFFSET_META_BLOCK_MARK_TABLE: ByteOffset = BYTES_META_SPACE as ByteOffset;
pub const OFFSET_META_LINE_MARK_TABLE: ByteOffset =
    OFFSET_META_BLOCK_MARK_TABLE + BYTES_META_BLOCK_MARK_TABLE as ByteOffset;
pub const OFFSET_META_GC_TABLE: ByteOffset =
    OFFSET_META_LINE_MARK_TABLE + BYTES_META_LINE_MARK_TABLE as ByteOffset;
pub const OFFSET_META_TYPE_TABLE: ByteOffset =
qinsoon's avatar
qinsoon committed
85 86 87
    OFFSET_META_GC_TABLE + BYTES_META_GC_TABLE as ByteOffset;
pub const OFFSET_MEM_START: ByteOffset =
    OFFSET_META_TYPE_TABLE + BYTES_META_TYPE_TABLE as ByteOffset;
88

89
#[repr(u8)]
90 91
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum LineMark {
92
    Free = 0,
93 94 95
    Live,
    FreshAlloc,
    ConservLive,
96
    PrevLive
97 98
}

99
#[repr(u8)]
100 101
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum BlockMark {
qinsoon's avatar
qinsoon committed
102
    Uninitialized = 0,
103
    Usable,
104
    Full
105
}