2008-11-17 13:32:35 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "../../../src/runtime/runtime.h"
|
|
|
|
|
|
|
|
typedef struct PageMap PageMap;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PageShift = 12,
|
|
|
|
PageMask = (1<<PageShift) - 1,
|
|
|
|
};
|
|
|
|
|
2008-12-05 16:24:18 -07:00
|
|
|
#define RefFree 0xffffffffU
|
|
|
|
#define RefManual 0xfffffffeU
|
|
|
|
#define RefStack 0xfffffffdU
|
|
|
|
|
2008-11-17 13:32:35 -07:00
|
|
|
enum {
|
|
|
|
PMBits = 64 - PageShift,
|
|
|
|
PMLevels = 4,
|
|
|
|
PMLevelBits = 13,
|
|
|
|
PMLevelSize = 1<<PMLevelBits,
|
|
|
|
PMLevelMask = PMLevelSize - 1,
|
|
|
|
};
|
|
|
|
struct PageMap
|
|
|
|
{
|
|
|
|
void *level0[PMLevelSize];
|
|
|
|
};
|
|
|
|
|
2008-12-05 16:24:18 -07:00
|
|
|
typedef struct Span Span;
|
|
|
|
typedef struct Central Central;
|
|
|
|
|
|
|
|
// A Span contains metadata about a range of pages.
|
|
|
|
enum {
|
|
|
|
SpanInUse = 0, // span has been handed out by allocator
|
|
|
|
SpanFree = 1, // span is in central free list
|
|
|
|
};
|
|
|
|
struct Span
|
|
|
|
{
|
|
|
|
Span *aprev; // in list of all spans
|
|
|
|
Span *anext;
|
|
|
|
|
|
|
|
Span *next; // in free lists
|
|
|
|
byte *base; // first byte in span
|
|
|
|
uintptr length; // number of pages in span
|
|
|
|
int32 cl;
|
|
|
|
int32 state; // state (enum above)
|
|
|
|
union {
|
|
|
|
int32 ref; // reference count if state == SpanInUse (for GC)
|
|
|
|
int32 *refbase; // ptr to packed ref counts
|
|
|
|
};
|
|
|
|
// void *type; // object type if state == SpanInUse (for GC)
|
|
|
|
};
|
|
|
|
|
|
|
|
// The Central cache contains a list of free spans,
|
|
|
|
// as well as free lists of small blocks.
|
|
|
|
struct Central
|
|
|
|
{
|
|
|
|
Lock;
|
|
|
|
Span *free[256];
|
|
|
|
Span *large; // free spans >= MaxPage pages
|
|
|
|
};
|
|
|
|
|
2008-12-04 22:04:26 -07:00
|
|
|
extern int64 allocator·allocated;
|
2008-11-17 13:32:35 -07:00
|
|
|
extern int64 allocator·footprint;
|
|
|
|
extern bool allocator·frozen;
|
|
|
|
|
|
|
|
void* trivalloc(int32);
|
|
|
|
void* pmlookup(PageMap*, uintptr);
|
|
|
|
void* pminsert(PageMap*, uintptr, void*);
|
2008-12-04 22:04:26 -07:00
|
|
|
|
|
|
|
void* alloc(int32);
|
|
|
|
void free(void*);
|
2008-12-05 16:24:18 -07:00
|
|
|
bool findobj(void*, void**, int64*, int32**);
|
|
|
|
|
|
|
|
extern Central central;
|
|
|
|
extern PageMap spanmap;
|
|
|
|
extern int32 classtosize[SmallFreeClasses];
|
|
|
|
extern Span *spanfirst, *spanlast;
|