[compiler-rt] r190606 - [asan] a bit of performance improvement in fake stack, generalized one test, fixed android build of another test
Kostya Serebryany
kcc at google.com
Thu Sep 12 07:41:10 PDT 2013
Author: kcc
Date: Thu Sep 12 09:41:10 2013
New Revision: 190606
URL: http://llvm.org/viewvc/llvm-project?rev=190606&view=rev
Log:
[asan] a bit of performance improvement in fake stack, generalized one test, fixed android build of another test
Modified:
compiler-rt/trunk/lib/asan/asan_fake_stack.cc
compiler-rt/trunk/lib/asan/asan_fake_stack.h
compiler-rt/trunk/lib/asan/lit_tests/TestCases/uar_and_exceptions.cc
compiler-rt/trunk/lib/asan/tests/asan_fake_stack_test.cc
Modified: compiler-rt/trunk/lib/asan/asan_fake_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_fake_stack.cc?rev=190606&r1=190605&r2=190606&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.cc Thu Sep 12 09:41:10 2013
@@ -22,6 +22,7 @@ void FakeStack::PoisonAll(u8 magic) {
magic);
}
+ALWAYS_INLINE USED
FakeFrame *FakeStack::Allocate(uptr stack_size_log, uptr class_id,
uptr real_stack) {
CHECK_LT(class_id, kNumberOfSizeClasses);
@@ -48,6 +49,7 @@ FakeFrame *FakeStack::Allocate(uptr stac
return 0;
}
+ALWAYS_INLINE USED
void FakeStack::Deallocate(FakeFrame *ff, uptr stack_size_log, uptr class_id,
uptr real_stack) {
u8 *base = GetFrame(stack_size_log, class_id, 0);
Modified: compiler-rt/trunk/lib/asan/asan_fake_stack.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_fake_stack.h?rev=190606&r1=190605&r2=190606&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.h (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.h Thu Sep 12 09:41:10 2013
@@ -55,8 +55,6 @@ struct FakeFrame {
// This allocator does not have quarantine per se, but it tries to allocate the
// frames in round robin fasion to maximize the delay between a deallocation
// and the next allocation.
-//
-// FIXME: handle throw/longjmp/clone, i.e. garbage collect the unwinded frames.
class FakeStack {
static const uptr kMinStackFrameSizeLog = 6; // Min frame is 64B.
static const uptr kMaxStackFrameSizeLog = 16; // Max stack frame is 64K.
Modified: compiler-rt/trunk/lib/asan/lit_tests/TestCases/uar_and_exceptions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/uar_and_exceptions.cc?rev=190606&r1=190605&r2=190606&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/uar_and_exceptions.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/uar_and_exceptions.cc Thu Sep 12 09:41:10 2013
@@ -5,22 +5,34 @@
volatile char *g;
+#ifndef FRAME_SIZE
+# define FRAME_SIZE 100
+#endif
+
+#ifndef NUM_ITER
+# define NUM_ITER 4000
+#endif
+
+#ifndef DO_THROW
+# define DO_THROW 1
+#endif
+
void Func(int depth) {
- char frame[100];
+ char frame[FRAME_SIZE];
g = &frame[0];
if (depth)
Func(depth - 1);
- else
+ else if (DO_THROW)
throw 1;
}
int main(int argc, char **argv) {
- for (int i = 0; i < 4000; i++) {
+ for (int i = 0; i < NUM_ITER; i++) {
try {
Func(argc * 100);
} catch(...) {
}
- if ((i % 1000) == 0)
+ if ((i % (NUM_ITER / 10)) == 0)
fprintf(stderr, "done [%d]\n", i);
}
return 0;
Modified: compiler-rt/trunk/lib/asan/tests/asan_fake_stack_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_fake_stack_test.cc?rev=190606&r1=190605&r2=190606&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_fake_stack_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_fake_stack_test.cc Thu Sep 12 09:41:10 2013
@@ -26,9 +26,9 @@
namespace __asan {
TEST(FakeStack, FlagsSize) {
- EXPECT_EQ(FakeStack::SizeRequiredForFlags(10), 1 << 5);
- EXPECT_EQ(FakeStack::SizeRequiredForFlags(11), 1 << 6);
- EXPECT_EQ(FakeStack::SizeRequiredForFlags(20), 1 << 15);
+ EXPECT_EQ(FakeStack::SizeRequiredForFlags(10), 1U << 5);
+ EXPECT_EQ(FakeStack::SizeRequiredForFlags(11), 1U << 6);
+ EXPECT_EQ(FakeStack::SizeRequiredForFlags(20), 1U << 15);
}
TEST(FakeStack, RequiredSize) {
@@ -36,11 +36,11 @@ TEST(FakeStack, RequiredSize) {
// uptr alloc_size = FakeStack::RequiredSize(i);
// printf("%zdK ==> %zd\n", 1 << (i - 10), alloc_size);
// }
- EXPECT_EQ(FakeStack::RequiredSize(15), 365568);
- EXPECT_EQ(FakeStack::RequiredSize(16), 727040);
- EXPECT_EQ(FakeStack::RequiredSize(17), 1449984);
- EXPECT_EQ(FakeStack::RequiredSize(18), 2895872);
- EXPECT_EQ(FakeStack::RequiredSize(19), 5787648);
+ EXPECT_EQ(FakeStack::RequiredSize(15), 365568U);
+ EXPECT_EQ(FakeStack::RequiredSize(16), 727040U);
+ EXPECT_EQ(FakeStack::RequiredSize(17), 1449984U);
+ EXPECT_EQ(FakeStack::RequiredSize(18), 2895872U);
+ EXPECT_EQ(FakeStack::RequiredSize(19), 5787648U);
}
TEST(FakeStack, FlagsOffset) {
@@ -69,23 +69,23 @@ TEST(FakeStack, CreateDestroy) {
}
TEST(FakeStack, ModuloNumberOfFrames) {
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, 0), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<15)), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<10)), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<9)), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<8)), 1<<8);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<15) + 1), 1);
-
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 1, 0), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 1, 1<<9), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 1, 1<<8), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 1, 1<<7), 1<<7);
-
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 0), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 1), 1);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 15), 15);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 16), 0);
- EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 17), 1);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, 0), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<15)), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<10)), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<9)), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<8)), 1U<<8);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 0, (1<<15) + 1), 1U);
+
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 1, 0), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 1, 1<<9), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 1, 1<<8), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 1, 1<<7), 1U<<7);
+
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 0), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 1), 1U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 15), 15U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 16), 0U);
+ EXPECT_EQ(FakeStack::ModuloNumberOfFrames(15, 5, 17), 1U);
}
TEST(FakeStack, GetFrame) {
@@ -95,9 +95,9 @@ TEST(FakeStack, GetFrame) {
u8 *base = fs->GetFrame(stack_size_log, 0, 0);
EXPECT_EQ(base, reinterpret_cast<u8 *>(fs) +
fs->SizeRequiredForFlags(stack_size_log) + 4096);
- EXPECT_EQ(base + 0*stack_size + 64 * 7, fs->GetFrame(stack_size_log, 0, 7));
- EXPECT_EQ(base + 1*stack_size + 128 * 3, fs->GetFrame(stack_size_log, 1, 3));
- EXPECT_EQ(base + 2*stack_size + 256 * 5, fs->GetFrame(stack_size_log, 2, 5));
+ EXPECT_EQ(base + 0*stack_size + 64 * 7, fs->GetFrame(stack_size_log, 0, 7U));
+ EXPECT_EQ(base + 1*stack_size + 128 * 3, fs->GetFrame(stack_size_log, 1, 3U));
+ EXPECT_EQ(base + 2*stack_size + 256 * 5, fs->GetFrame(stack_size_log, 2, 5U));
fs->Destroy();
}
More information about the llvm-commits
mailing list