Permalink
Browse files

cleanup, ENABLE_CONTROL_FRAME_STATISTICS

  • Loading branch information...
1 parent 8e21292 commit 94ddc3f3abf69d7390b38bedd96d47b7fa56cae1 @gnooth committed Mar 29, 2011
Showing with 26 additions and 58 deletions.
  1. +1 −1 kernel/Frame.cpp
  2. +10 −11 kernel/Frame.hpp
  3. +15 −32 kernel/Thread.cpp
  4. +0 −14 kernel/catch.cpp
View
@@ -66,7 +66,7 @@ void RT_unwind_to(Frame * frame, Thread * thread)
else
uwp->run_cleanup_forms(thread);
}
- else if (type == BLOCK || type == TAGBODY || type == CATCH)
+ else
thread->release_frame(f);
f = next;
}
View
@@ -19,6 +19,8 @@
#ifndef __FRAME_HPP
#define __FRAME_HPP
+// #define ENABLE_CONTROL_FRAME_STATISTICS
+
class UnwindProtect;
enum FrameType
@@ -274,6 +276,7 @@ class FramePool : public gc
void print_statistics()
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
printf("Pool statistics:\n");
printf(" released = %lu (block = %lu, tagbody = %lu, unwind_protect = %lu, catch = %lu)\n",
_number_released, _number_released_block, _number_released_tagbody,
@@ -283,30 +286,25 @@ class FramePool : public gc
printf(" new = %lu\n", _number_new);
printf(" index = %u\n", _index);
printf(" max_index = %u\n", _max_index);
+#endif
}
Frame * get_frame()
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
if (_index > 0)
_number_reused++;
else
_number_new++;
+#endif
return _index > 0 ? _pool[--_index] : NULL;
}
void release_frame(Frame * frame)
{
-// for (unsigned int i = 0; i < _index; i++)
-// {
-// if (_pool[i] == frame)
-// {
-// printf("frame already in pool\n");
-// extern Value SYS_int3();
-// SYS_int3();
-// }
-// }
if (_index < FRAME_POOL_SIZE - 1)
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
_number_released++;
FrameType type = frame->type();
if (type == TAGBODY)
@@ -317,15 +315,16 @@ class FramePool : public gc
_number_released_unwind_protect++;
else if (type == CATCH)
_number_released_catch++;
+#endif
frame->clear();
_pool[_index++] = frame;
if (_index > _max_index)
_max_index = _index;
}
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
else
_number_ignored++;
-// if (_index && !(_index % 10))
-// printf("release_frame _index = %d\n", _index);
+#endif
}
};
View
@@ -245,42 +245,48 @@ Tagbody * Thread::get_tagbody()
void Thread::print_statistics()
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
_frame_pool->print_statistics();
printf("add_block_calls = %lu\n", _number_add_block_calls);
printf("get_tagbody_calls = %lu\n", _number_get_tagbody_calls);
printf("new_tagbody_calls = %lu\n", _number_new_tagbody_calls);
printf("add_unwind_protect_calls = %lu\n", _number_add_unwind_protect_calls);
printf("add_catch_frame_calls = %lu\n", _number_add_catch_frame_calls);
fflush(stdout);
+#endif
}
// ### thread-statistics
Value SYS_thread_statistics()
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
current_thread()->print_statistics();
+#else
+ printf("unsupported\n");
+ fflush(stdout);
+#endif
return current_thread()->set_values();
}
Block * Thread::add_block(Value name)
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
_number_add_block_calls++;
+#endif
Block * block = (Block *) get_frame();
block->set_type(BLOCK);
block->init(this);
block->set_name(name);
- if (block == _last_control_frame)
- {
- printf("Thread::add_block() block == _last_control_frame\n");
- extern Value SYS_int3();
- }
block->set_next(_last_control_frame);
_last_control_frame = block;
return block;
}
UnwindProtect * Thread::add_unwind_protect(Value cleanup_forms, Environment * env)
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
_number_add_unwind_protect_calls++;
+#endif
UnwindProtect * uwp = (UnwindProtect *) get_frame();
uwp->set_type(UNWIND_PROTECT);
uwp->init(this, cleanup_forms, env);
@@ -291,7 +297,9 @@ UnwindProtect * Thread::add_unwind_protect(Value cleanup_forms, Environment * en
UnwindProtect * Thread::add_unwind_protect(void * code, long bp)
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
_number_add_unwind_protect_calls++;
+#endif
UnwindProtect * uwp = (UnwindProtect *) get_frame();
uwp->set_type(UNWIND_PROTECT);
uwp->init(this, code, bp);
@@ -410,43 +418,18 @@ Tag * Thread::find_tag(Tagbody * tagbody, int index)
Catch * Thread::add_catch_frame(Value tag)
{
+#ifdef ENABLE_CONTROL_FRAME_STATISTICS
_number_add_catch_frame_calls++;
-// Frame * frame = _frame_pool->get_frame();
-// if (frame)
-// {
-// frame->set_type(TAGBODY);
-// frame->init(this);
-// if (frame == _last_control_frame)
-// {
-// printf("Thread::get_tagbody() frame == _last_control_frame\n");
-// extern Value SYS_int3();
-// }
-// frame->set_next(_last_control_frame);
-// _last_control_frame = frame;
-// return (Tagbody *) frame;
-// }
-// _number_new_tagbody_calls++;
-// return new Tagbody(this);
+#endif
Catch * catch_frame = (Catch *) get_frame();
catch_frame->set_type(CATCH);
catch_frame->init(this);
catch_frame->set_tag(tag);
- if (catch_frame == _last_control_frame)
- {
- printf("Thread::add_catch_frame() catch_frame == _last_control_frame\n");
- extern Value SYS_int3();
- }
catch_frame->set_next(_last_control_frame);
_last_control_frame = catch_frame;
return catch_frame;
}
-// Catch * Thread::add_catch_frame(Value tag)
-// {
-// _last_control_frame = new Catch(tag, _last_control_frame, this);
-// return (Catch *) _last_control_frame;
-// }
-
Frame * Thread::find_catch_frame(Value tag)
{
Frame * frame = _last_control_frame;
View
@@ -44,7 +44,6 @@ Value CL_catch(Value args, Environment * env, Thread * thread)
StackFrame * saved_stack = thread->stack();
unsigned int saved_call_depth = thread->call_depth();
#endif
-// Catch * catch_frame = thread->add_catch_frame(tag); // RT_enter_catch
Catch * catch_frame = RT_enter_catch(thread, tag);
assert(catch_frame->type() == CATCH);
if (SETJMP(*catch_frame->jmp()) == 0)
@@ -59,25 +58,12 @@ Value CL_catch(Value args, Environment * env, Thread * thread)
}
assert(thread->stack() == saved_stack);
assert(thread->call_depth() == saved_call_depth);
-// thread->set_last_control_frame(catch_frame->last_control_frame()); // RT_leave_catch
RT_leave_catch(thread, catch_frame);
return result;
}
else
{
// caught THROW
-// thread->set_stack(saved_stack);
-// thread->set_call_depth(saved_call_depth);
-// thread->set_last_control_frame(catch_frame->last_control_frame()); // added
-// thread->set_last_tag(catch_frame->last_tag());
-// int values_length = thread->values_length();
-// assert(values_length >= 0);
-// if (values_length == 0)
-// return NIL;
-// Value result = thread->nth_value(0);
-// if (values_length == 1)
-// thread->clear_values();
-// return result;
return RT_caught_throw(thread, catch_frame);
}
}

0 comments on commit 94ddc3f

Please sign in to comment.