Skip to content

Commit ae02e17

Browse files
authored
Make GC and config output optional (#69)
- remove duplicate output of GC time, and respect the verbosity setting with the `-g` flag - add `-cfg` flag to print VM compilation settings only on demand
2 parents a934e9a + 2e09be5 commit ae02e17

3 files changed

Lines changed: 46 additions & 40 deletions

File tree

src/Main.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,6 @@
3838
int32_t main(int32_t argc, char** argv) {
3939
cout << "This is SOM++" << endl;
4040

41-
if (GC_TYPE == GENERATIONAL) {
42-
cout << "\tgarbage collector: generational" << endl;
43-
} else if (GC_TYPE == COPYING) {
44-
cout << "\tgarbage collector: copying" << endl;
45-
} else if (GC_TYPE == MARK_SWEEP) {
46-
cout << "\tgarbage collector: mark-sweep" << endl;
47-
} else if (GC_TYPE == DEBUG_COPYING) {
48-
cout << "\tgarbage collector: debug copying" << endl;
49-
} else {
50-
cout << "\tgarbage collector: unknown" << endl;
51-
}
52-
53-
if (USE_TAGGING) {
54-
cout << "\twith tagged integers" << endl;
55-
} else {
56-
cout << "\tnot tagging integers" << endl;
57-
}
58-
59-
if (CACHE_INTEGER) {
60-
cout << "\tcaching integers from " << INT_CACHE_MIN_VALUE << " to "
61-
<< INT_CACHE_MAX_VALUE << endl;
62-
} else {
63-
cout << "\tnot caching integers" << endl;
64-
}
65-
66-
cout << "--------------------------------------" << endl;
67-
6841
Universe::Start(argc, argv);
6942

7043
Quit(ERR_SUCCESS);

src/vm/Print.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ __attribute__((noreturn)) __attribute__((noinline)) void ErrorExit(
4141
}
4242

4343
__attribute__((noreturn)) __attribute__((noinline)) void Quit(int32_t err) {
44-
ErrorPrint("Time spent in GC: [" +
45-
to_string(Timer::GCTimer.GetTotalTime()) + "] msec\n");
46-
4744
Universe::Shutdown();
4845

4946
OutputAllocationLogFile();

src/vm/Universe.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ void Universe::BasicInit() {
9393
}
9494

9595
void Universe::Shutdown() {
96-
ErrorPrint("Time spent in GC: [" +
97-
to_string(Timer::GCTimer.GetTotalTime()) + "] msec\n");
96+
if (gcVerbosity > 0) {
97+
ErrorPrint("Time spent in GC: [" +
98+
to_string(Timer::GCTimer.GetTotalTime()) + "] msec\n");
99+
}
100+
98101
#ifdef GENERATE_INTEGER_HISTOGRAM
99102
std::string file_name_hist = std::string(bm_name);
100103
file_name_hist.append("_integer_histogram.csv");
@@ -138,6 +141,35 @@ void Universe::Shutdown() {
138141
#endif
139142
}
140143

144+
static void printVmConfig() {
145+
if (GC_TYPE == GENERATIONAL) {
146+
cout << "\tgarbage collector: generational\n";
147+
} else if (GC_TYPE == COPYING) {
148+
cout << "\tgarbage collector: copying\n";
149+
} else if (GC_TYPE == MARK_SWEEP) {
150+
cout << "\tgarbage collector: mark-sweep\n";
151+
} else if (GC_TYPE == DEBUG_COPYING) {
152+
cout << "\tgarbage collector: debug copying\n";
153+
} else {
154+
cout << "\tgarbage collector: unknown\n";
155+
}
156+
157+
if (USE_TAGGING) {
158+
cout << "\twith tagged integers\n";
159+
} else {
160+
cout << "\tnot tagging integers\n";
161+
}
162+
163+
if (CACHE_INTEGER) {
164+
cout << "\tcaching integers from " << INT_CACHE_MIN_VALUE << " to "
165+
<< INT_CACHE_MAX_VALUE << "\n";
166+
} else {
167+
cout << "\tnot caching integers\n";
168+
}
169+
170+
cout << "--------------------------------------\n";
171+
}
172+
141173
vector<std::string> Universe::handleArguments(int32_t argc, char** argv) {
142174
vector<std::string> vmArgs = vector<std::string>();
143175
dumpBytecodes = 0;
@@ -151,6 +183,8 @@ vector<std::string> Universe::handleArguments(int32_t argc, char** argv) {
151183
setupClassPath(std::string(argv[++i]));
152184
} else if (strncmp(argv[i], "-d", 2) == 0) {
153185
++dumpBytecodes;
186+
} else if (strncmp(argv[i], "-cfg", 4) == 0) {
187+
printVmConfig();
154188
} else if (strncmp(argv[i], "-g", 2) == 0) {
155189
++gcVerbosity;
156190
} else if (strncmp(argv[i], "-H", 2) == 0) {
@@ -235,14 +269,16 @@ void Universe::addClassPath(const std::string& cp) {
235269
void Universe::printUsageAndExit(char* executable) {
236270
cout << "Usage: " << executable << " [-options] [args...]\n\n";
237271
cout << "where options include:\n";
238-
cout << " -cp <directories separated by " << pathSeparator << ">\n";
239-
cout << " set search path for application classes\n";
240-
cout << " -d enable disassembling (twice for tracing)\n";
241-
cout << " -g enable garbage collection details:\n"
242-
<< " 1x - print statistics when VM shuts down\n"
243-
<< " 2x - print statistics upon each collection\n"
244-
<< " 3x - print statistics and dump heap upon each \n"
245-
<< "collection\n";
272+
cout << " -cp <directories separated by " << pathSeparator << ">\n";
273+
cout << " set search path for application classes\n";
274+
cout << " -d enable disassembling (twice for tracing)\n";
275+
cout << " -cfg print VM configuration\n";
276+
cout
277+
<< " -g enable garbage collection details:\n"
278+
<< " 1x - print statistics when VM shuts down\n"
279+
<< " 2x - print statistics upon each collection\n"
280+
<< " 3x - print statistics and dump heap upon each collection\n"
281+
<< "\n";
246282
cout << " -HxMB set the heap size to x MB (default: 1 MB)\n";
247283
cout << " -HxKB set the heap size to x KB (default: 1 MB)\n";
248284
cout << " -h show this help\n";

0 commit comments

Comments
 (0)