// license that can be found in the LICENSE file.
#include "runtime.h"
+#include "arch_GOARCH.h"
+#include "malloc.h"
#include "hashmap.h"
#include "type.h"
#include "race.h"
h = runtime·mal(sizeof(*h));
h->flag |= CanFreeTable; /* until reflect gets involved, free is okay */
+ if(UseSpanType) {
+ if(false) {
+ runtime·printf("makemap %S: %p\n", *typ->string, h);
+ }
+ runtime·settype(h, (uintptr)typ | TypeInfo_Map);
+ }
+
ksize = ROUND(key->size, sizeof(void*));
vsize = ROUND(val->size, sizeof(void*));
if(ksize > MaxData || vsize > MaxData || ksize+vsize > MaxData) {
reflect·unsafe_New(Eface typ, void *ret)
{
Type *t;
+ uint32 flag;
// Reflect library has reinterpreted typ
// as its own kind of type structure.
// type structure sits before the data pointer.
t = (Type*)((Eface*)typ.data-1);
- if(t->kind&KindNoPointers)
- ret = runtime·mallocgc(t->size, FlagNoPointers, 1, 1);
- else
- ret = runtime·mal(t->size);
+ flag = t->kind&KindNoPointers ? FlagNoPointers : 0;
+ ret = runtime·mallocgc(t->size, flag, 1, 1);
+
+ if(UseSpanType && !flag) {
+ if(false) {
+ runtime·printf("unsafe_New %S: %p\n", *t->string, ret);
+ }
+ runtime·settype(ret, (uintptr)t | TypeInfo_SingleObject);
+ }
+
FLUSH(&ret);
}
t = (Type*)((Eface*)typ.data-1);
size = n*t->size;
- if(t->kind&KindNoPointers)
+ if(size == 0)
+ ret = (byte*)&runtime·zerobase;
+ else if(t->kind&KindNoPointers)
ret = runtime·mallocgc(size, FlagNoPointers, 1, 1);
- else
- ret = runtime·mal(size);
+ else {
+ ret = runtime·mallocgc(size, 0, 1, 1);
+
+ if(UseSpanType) {
+ if(false) {
+ runtime·printf("unsafe_NewArray [%D]%S: %p\n", (int64)n, *t->string, ret);
+ }
+ runtime·settype(ret, (uintptr)t | TypeInfo_Array);
+ }
+ }
+
FLUSH(&ret);
}
FLUSH(&ret);
}
+// same as runtime·new, but callable from C
+void*
+runtime·cnew(Type *typ)
+{
+ uint32 flag;
+ void *ret;
+
+ m->racepc = runtime·getcallerpc(&typ);
+ flag = typ->kind&KindNoPointers ? FlagNoPointers : 0;
+ ret = runtime·mallocgc(typ->size, flag, 1, 1);
+
+ if(UseSpanType && !flag) {
+ if(false) {
+ runtime·printf("new %S: %p\n", *typ->string, ret);
+ }
+ runtime·settype(ret, (uintptr)typ | TypeInfo_SingleObject);
+ }
+ return ret;
+}
+
void*
runtime·stackalloc(uint32 n)
{
bool runtime·blockspecial(void*);
void runtime·setblockspecial(void*, bool);
void runtime·purgecachedstats(MCache*);
+void* runtime·cnew(Type*);
void runtime·settype(void*, uintptr);
void runtime·settype_flush(M*, bool);
// Enables type information at the end of blocks allocated from heap
DebugTypeAtBlockEnd = 0,
};
+
+// defined in mgc0.go
+void runtime·gc_m_ptr(Eface*);
--- /dev/null
+// Copyright 2012 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.
+
+package runtime
+
+// Called from C. Returns the Go type *m.
+func gc_m_ptr(ret *interface{}) {
+ *ret = (*m)(nil)
+}
#include "os_GOOS.h"
#include "stack.h"
#include "race.h"
+#include "type.h"
bool runtime·iscgo;
runtime·newm(void)
{
M *mp;
+ static Type *mtype; // The Go type M
- mp = runtime·malloc(sizeof(M));
+ if(mtype == nil) {
+ Eface e;
+ runtime·gc_m_ptr(&e);
+ mtype = ((PtrType*)e.type)->elem;
+ }
+
+ mp = runtime·cnew(mtype);
mcommoninit(mp);
if(runtime·iscgo) {
* external data
*/
extern String runtime·emptystring;
+extern uintptr runtime·zerobase;
G* runtime·allg;
G* runtime·lastg;
M* runtime·allm;
// Dummy word to use as base pointer for make([]T, 0).
// Since you cannot take the address of such a slice,
// you can't tell that they all have the same base pointer.
-static uintptr zerobase;
+uintptr runtime·zerobase;
static void
makeslice1(SliceType *t, intgo len, intgo cap, Slice *ret)
ret->len = len;
ret->cap = cap;
- if(cap == 0)
- ret->array = (byte*)&zerobase;
+ if(size == 0)
+ ret->array = (byte*)&runtime·zerobase;
else if((t->elem->kind&KindNoPointers))
ret->array = runtime·mallocgc(size, FlagNoPointers, 1, 1);
- else
- ret->array = runtime·mal(size);
+ else {
+ ret->array = runtime·mallocgc(size, 0, 1, 1);
+
+ if(UseSpanType) {
+ if(false) {
+ runtime·printf("new slice [%D]%S: %p\n", (int64)cap, *t->elem->string, ret->array);
+ }
+ runtime·settype(ret->array, (uintptr)t->elem | TypeInfo_Array);
+ }
+ }
}
// appendslice(type *Type, x, y, []T) []T
typedef struct IMethod IMethod;
typedef struct SliceType SliceType;
typedef struct FuncType FuncType;
+typedef struct PtrType PtrType;
// Needs to be in sync with typekind.h/CommonSize
struct CommonType
Slice in;
Slice out;
};
+
+struct PtrType
+{
+ Type;
+ Type *elem;
+};