Fix PR #.
[official-gcc.git] / libgo / runtime / mgc0.h
blob16000d1ae2ea8b7ce613a55455e376d460bff270
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Garbage collector (GC)
7 // GC instruction opcodes.
8 //
9 // The opcode of an instruction is followed by zero or more
10 // arguments to the instruction.
12 // Meaning of arguments:
13 // off Offset (in bytes) from the start of the current object
14 // objgc Pointer to GC info of an object
15 // objgcrel Offset to GC info of an object
16 // len Length of an array
17 // elemsize Size (in bytes) of an element
18 // size Size (in bytes)
20 // NOTE: There is a copy of these in ../reflect/type.go.
21 // They must be kept in sync.
22 enum {
23 GC_END, // End of object, loop or subroutine. Args: none
24 GC_PTR, // A typed pointer. Args: (off, objgc)
25 GC_APTR, // Pointer to an arbitrary object. Args: (off)
26 GC_ARRAY_START, // Start an array with a fixed length. Args: (off, len, elemsize)
27 GC_ARRAY_NEXT, // The next element of an array. Args: none
28 GC_CALL, // Call a subroutine. Args: (off, objgcrel)
29 GC_CHAN_PTR, // Go channel. Args: (off, ChanType*)
30 GC_STRING, // Go string. Args: (off)
31 GC_EFACE, // interface{}. Args: (off)
32 GC_IFACE, // interface{...}. Args: (off)
33 GC_SLICE, // Go slice. Args: (off, objgc)
34 GC_REGION, // A region/part of the current object. Args: (off, size, objgc)
36 GC_NUM_INSTR, // Number of instruction opcodes
39 enum {
40 // Size of GC's fixed stack.
42 // The current GC implementation permits:
43 // - at most 1 stack allocation because of GC_CALL
44 // - at most GC_STACK_CAPACITY allocations because of GC_ARRAY_START
45 GC_STACK_CAPACITY = 8,
48 enum {
49 ScanStackByFrames = 1,
50 IgnorePreciseGC = 0,
52 // Four bits per word (see #defines below).
53 wordsPerBitmapWord = sizeof(void*)*8/4,
54 bitShift = sizeof(void*)*8/4,
57 // Bits in per-word bitmap.
58 // #defines because enum might not be able to hold the values.
60 // Each word in the bitmap describes wordsPerBitmapWord words
61 // of heap memory. There are 4 bitmap bits dedicated to each heap word,
62 // so on a 64-bit system there is one bitmap word per 16 heap words.
63 // The bits in the word are packed together by type first, then by
64 // heap location, so each 64-bit bitmap word consists of, from top to bottom,
65 // the 16 bitMarked bits for the corresponding heap words,
66 // then the 16 bitScan/bitBlockBoundary bits, then the 16 bitAllocated bits.
67 // This layout makes it easier to iterate over the bits of a given type.
69 // The bitmap starts at mheap.arena_start and extends *backward* from
70 // there. On a 64-bit system the off'th word in the arena is tracked by
71 // the off/16+1'th word before mheap.arena_start. (On a 32-bit system,
72 // the only difference is that the divisor is 8.)
74 // To pull out the bits corresponding to a given pointer p, we use:
76 // off = p - (uintptr*)mheap.arena_start; // word offset
77 // b = (uintptr*)mheap.arena_start - off/wordsPerBitmapWord - 1;
78 // shift = off % wordsPerBitmapWord
79 // bits = *b >> shift;
80 // /* then test bits & bitAllocated, bits & bitMarked, etc. */
82 #define bitAllocated ((uintptr)1<<(bitShift*0)) /* block start; eligible for garbage collection */
83 #define bitScan ((uintptr)1<<(bitShift*1)) /* when bitAllocated is set */
84 #define bitMarked ((uintptr)1<<(bitShift*2)) /* when bitAllocated is set */
85 #define bitBlockBoundary ((uintptr)1<<(bitShift*1)) /* when bitAllocated is NOT set - mark for FlagNoGC objects */
87 #define bitMask (bitAllocated | bitScan | bitMarked)