forked from dolphinsmalltalk/DolphinVM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnapshotPrim.cpp
More file actions
95 lines (76 loc) · 2.38 KB
/
SnapshotPrim.cpp
File metadata and controls
95 lines (76 loc) · 2.38 KB
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
/******************************************************************************
File: SnapshotPrim.cpp
Description:
Implementation of the Interpreter class' snapshot/quit primitive methods
******************************************************************************/
#include "Ist.h"
#ifndef _DEBUG
#pragma optimize("s", on)
#pragma auto_inline(off)
#endif
#if defined(TO_GO)
#error To Go VMs should not be able to snapshot the image
#endif
#include "ObjMem.h"
#include "Interprt.h"
#include "InterprtPrim.inl"
#include "InterprtProc.inl"
// Smalltalk classes
#include "STString.h"
#pragma auto_inline(off)
BOOL __fastcall Interpreter::primitiveSnapshot(CompiledMethod& , unsigned argCount)
{
Oop arg = stackValue(argCount-1);
char* szFileName;
if (arg == Oop(Pointers.Nil))
szFileName = 0;
else if (ObjectMemory::fetchClassOf(arg) == Pointers.ClassString)
{
StringOTE* oteString = reinterpret_cast<StringOTE*>(arg);
String* fileName = oteString->m_location;
szFileName = fileName->m_characters;
}
else
return primitiveFailure(0);
bool bBackup;
if (argCount >= 2)
bBackup = reinterpret_cast<OTE*>(stackValue(argCount-2)) == Pointers.True;
else
bBackup = false;
SMALLINTEGER nCompressionLevel;
if (argCount >= 3)
{
Oop oopCompressionLevel = stackValue(argCount-3);
nCompressionLevel = ObjectMemoryIsIntegerObject(oopCompressionLevel)?ObjectMemoryIntegerValueOf(oopCompressionLevel):0;
}
else
nCompressionLevel = 0;
// N.B. It is not necessary to clear down the memory pools as the free list is rebuild on every image
// load and the pool members, though not on the free list at present, are marked as free entries
// in the object table
// ZCT is reconciled, so objects may be deleted
flushAtCaches();
// Store the active frame of the active process before saving so available on image reload
// We're not actually suspending the process now, but it appears like that to the snapshotted
// image on restarting
m_registers.PrepareToSuspendProcess();
#ifdef OAD
DWORD timeStart = timeGetTime();
#endif
int saveResult = ObjectMemory::SaveImageFile(szFileName, bBackup, nCompressionLevel);
#ifdef OAD
DWORD timeEnd = timeGetTime();
TRACESTREAM << "Time to save image: " << (timeEnd - timeStart) << " mS" << endl;
#endif
if (!saveResult)
{
// Success
popStack();
return primitiveSuccess();
}
else
{
// Failure
return primitiveFailure(saveResult);
}
}