-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathGCPrim.cpp
194 lines (160 loc) · 4.3 KB
/
GCPrim.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/******************************************************************************
File: GCPrim.cpp
Description:
Implementation of the Interpreter class' GC primitive methods
******************************************************************************/
#include "Ist.h"
#ifndef _DEBUG
#pragma optimize("s", on)
#pragma auto_inline(off)
#endif
#pragma code_seg(GC_SEG)
#include "ObjMem.h"
#include "Interprt.h"
#include "InterprtPrim.inl"
// Smalltalk objects
#include "STMethod.h"
#include "STBlockClosure.h"
bool Interpreter::disableAsyncGC(bool bDisable)
{
if (bDisable == m_bAsyncGCDisabled) return bDisable;
m_bAsyncGCDisabled = bDisable;
if (!m_bAsyncGCDisabled)
{
// If previously disabled, may be OT overflow interrupts pending that we should consolidate
// into one
if (m_nOTOverflows > 0)
{
m_nOTOverflows = 0;
CHECKREFERENCES
queueInterrupt(VMI_OTOVERFLOW, ObjectMemoryIntegerObjectOf(ObjectMemory::GetOTSize()));
}
return true;
}
else
return false;
}
void Interpreter::NotifyOTOverflow()
{
if (m_bAsyncGCDisabled)
{
m_nOTOverflows++;
}
else
{
CHECKREFERENCES
queueInterrupt(VMI_OTOVERFLOW, ObjectMemoryIntegerObjectOf(ObjectMemory::GetOTSize()));
}
}
void Interpreter::syncGC(DWORD gcFlags)
{
asyncGC(gcFlags);
CheckProcessSwitch();
}
void Interpreter::asyncGC(DWORD gcFlags)
{
if (m_bAsyncGCDisabled)
{
m_nOTOverflows++;
return;
}
resizeActiveProcess();
#ifdef _DEBUG
if (Interpreter::executionTrace != 0)
{
for (unsigned i=0;i<NUMOTEPOOLS;i++)
m_otePools[i].DumpStats();
}
#endif
ObjectMemory::asyncGC(gcFlags, m_registers.m_stackPointer);
}
#ifndef _DEBUG
#pragma auto_inline(on)
#endif
// This has been usurped for GC primitive
Oop* __fastcall Interpreter::primitiveCoreLeft(Oop* const sp , unsigned argCount)
{
CHECKREFERENCESSP(sp);
DWORD gcFlags = 0;
if (argCount)
{
ASSERT(argCount == 1);
Oop intPointer = *sp;
ASSERT(ObjectMemoryIsIntegerObject(intPointer));
gcFlags = ObjectMemoryIntegerValueOf(intPointer);
m_registers.m_stackPointer -= argCount;
}
syncGC(gcFlags);
return m_registers.m_stackPointer;
}
#ifdef _DEBUG
void Interpreter::DumpOTEPoolStats()
{
for (unsigned i=0;i<NUMOTEPOOLS;i++)
m_otePools[i].DumpStats();
}
#endif
void Interpreter::freePools()
{
#if defined(_DEBUG) && defined(VMDLL)
{
tracelock lock(TRACESTREAM);
TRACESTREAM<< L"Clearing down OTE pools. Stats before clear..." << std::endl;
}
#endif
// Must first adjust context size back to normal for free
// in case from a pool (avoids freeing mem back to smaller pool)
{
OTE* ote = m_otePools[CONTEXTPOOL].m_pFreeList;
const MWORD sizeOfPoolContext = SizeOfPointers(Context::FixedSize+Context::MaxEnvironmentTemps);
while (ote)
{
VariantObject* obj = static_cast<VariantObject*>(ote->m_location);
ote->setSize(sizeOfPoolContext);
ote = reinterpret_cast<OTE*>(obj->m_fields[0]);
}
}
{
OTE* ote = m_otePools[BLOCKPOOL].m_pFreeList;
const MWORD sizeOfPoolBlock = SizeOfPointers(BlockClosure::FixedSize+BlockClosure::MaxCopiedValues);
while (ote)
{
VariantObject* obj = static_cast<VariantObject*>(ote->m_location);
ote->setSize(sizeOfPoolBlock);
ote = (OTE*)obj->m_fields[0];
}
}
#ifdef _DEBUG
//DumpOTEPoolStats();
#endif
for (unsigned i=0;i<NUMOTEPOOLS;i++)
m_otePools[i].clear();
#if defined(_DEBUG) && defined(VMDLL)
{
tracelock lock(TRACESTREAM);
TRACESTREAM << std::endl;
}
#endif
}
Oop* __fastcall Interpreter::primitiveOopsLeft(Oop* const sp, unsigned)
{
// Ensure active process has the correct size and that the Zct is empty
// and all ref counts are correct
resizeActiveProcess();
// Compact will perform a GC, and will also change the Oops of objects
// so any that are saved down in Smalltalk will be invalidated.
GrabAsyncProtect();
// It is OK for compact to perform additional GrabAsyncProtects()
SMALLINTEGER oopsLeft = ObjectMemory::compact(sp);
RelinquishAsyncProtect();
// compact() returns -1 if unable to reserve space for a new OT. This can happen
// if a very large maximum object setting is used on a machine with relatively little
// virtual memory
if (oopsLeft < 0)
return primitiveFailure(1);
// Adjust stack before any process switch!
*sp = ObjectMemoryIntegerObjectOf(oopsLeft);
// N.B. May cause a process switch
CheckProcessSwitch();
return m_registers.m_stackPointer;
}