You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by hb...@apache.org on 2017/01/17 19:31:03 UTC
[09/51] [partial] incubator-quickstep git commit: Added shell script
to download prerequisite third party libs
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/stacktrace_x86-inl.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/stacktrace_x86-inl.h b/third_party/gperftools/src/stacktrace_x86-inl.h
deleted file mode 100644
index 46eb5d8..0000000
--- a/third_party/gperftools/src/stacktrace_x86-inl.h
+++ /dev/null
@@ -1,354 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-//
-// Produce stack trace
-
-#ifndef BASE_STACKTRACE_X86_INL_H_
-#define BASE_STACKTRACE_X86_INL_H_
-// Note: this file is included into stacktrace.cc more than once.
-// Anything that should only be defined once should be here:
-
-#include "config.h"
-#include <stdlib.h> // for NULL
-#include <assert.h>
-#if defined(HAVE_SYS_UCONTEXT_H)
-#include <sys/ucontext.h>
-#elif defined(HAVE_UCONTEXT_H)
-#include <ucontext.h> // for ucontext_t
-#elif defined(HAVE_CYGWIN_SIGNAL_H)
-// cygwin/signal.h has a buglet where it uses pthread_attr_t without
-// #including <pthread.h> itself. So we have to do it.
-# ifdef HAVE_PTHREAD
-# include <pthread.h>
-# endif
-#include <cygwin/signal.h>
-typedef ucontext ucontext_t;
-#endif
-#ifdef HAVE_STDINT_H
-#include <stdint.h> // for uintptr_t
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_MMAP
-#include <sys/mman.h> // for msync
-#include "base/vdso_support.h"
-#endif
-
-#include "gperftools/stacktrace.h"
-
-#if defined(__linux__) && defined(__i386__) && defined(__ELF__) && defined(HAVE_MMAP)
-// Count "push %reg" instructions in VDSO __kernel_vsyscall(),
-// preceding "syscall" or "sysenter".
-// If __kernel_vsyscall uses frame pointer, answer 0.
-//
-// kMaxBytes tells how many instruction bytes of __kernel_vsyscall
-// to analyze before giving up. Up to kMaxBytes+1 bytes of
-// instructions could be accessed.
-//
-// Here are known __kernel_vsyscall instruction sequences:
-//
-// SYSENTER (linux-2.6.26/arch/x86/vdso/vdso32/sysenter.S).
-// Used on Intel.
-// 0xffffe400 <__kernel_vsyscall+0>: push %ecx
-// 0xffffe401 <__kernel_vsyscall+1>: push %edx
-// 0xffffe402 <__kernel_vsyscall+2>: push %ebp
-// 0xffffe403 <__kernel_vsyscall+3>: mov %esp,%ebp
-// 0xffffe405 <__kernel_vsyscall+5>: sysenter
-//
-// SYSCALL (see linux-2.6.26/arch/x86/vdso/vdso32/syscall.S).
-// Used on AMD.
-// 0xffffe400 <__kernel_vsyscall+0>: push %ebp
-// 0xffffe401 <__kernel_vsyscall+1>: mov %ecx,%ebp
-// 0xffffe403 <__kernel_vsyscall+3>: syscall
-//
-// i386 (see linux-2.6.26/arch/x86/vdso/vdso32/int80.S)
-// 0xffffe400 <__kernel_vsyscall+0>: int $0x80
-// 0xffffe401 <__kernel_vsyscall+1>: ret
-//
-static const int kMaxBytes = 10;
-
-// We use assert()s instead of DCHECK()s -- this is too low level
-// for DCHECK().
-
-static int CountPushInstructions(const unsigned char *const addr) {
- int result = 0;
- for (int i = 0; i < kMaxBytes; ++i) {
- if (addr[i] == 0x89) {
- // "mov reg,reg"
- if (addr[i + 1] == 0xE5) {
- // Found "mov %esp,%ebp".
- return 0;
- }
- ++i; // Skip register encoding byte.
- } else if (addr[i] == 0x0F &&
- (addr[i + 1] == 0x34 || addr[i + 1] == 0x05)) {
- // Found "sysenter" or "syscall".
- return result;
- } else if ((addr[i] & 0xF0) == 0x50) {
- // Found "push %reg".
- ++result;
- } else if (addr[i] == 0xCD && addr[i + 1] == 0x80) {
- // Found "int $0x80"
- assert(result == 0);
- return 0;
- } else {
- // Unexpected instruction.
- assert(0 == "unexpected instruction in __kernel_vsyscall");
- return 0;
- }
- }
- // Unexpected: didn't find SYSENTER or SYSCALL in
- // [__kernel_vsyscall, __kernel_vsyscall + kMaxBytes) interval.
- assert(0 == "did not find SYSENTER or SYSCALL in __kernel_vsyscall");
- return 0;
-}
-#endif
-
-// Given a pointer to a stack frame, locate and return the calling
-// stackframe, or return NULL if no stackframe can be found. Perform sanity
-// checks (the strictness of which is controlled by the boolean parameter
-// "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned.
-template<bool STRICT_UNWINDING, bool WITH_CONTEXT>
-static void **NextStackFrame(void **old_sp, const void *uc) {
- void **new_sp = (void **) *old_sp;
-
-#if defined(__linux__) && defined(__i386__) && defined(HAVE_VDSO_SUPPORT)
- if (WITH_CONTEXT && uc != NULL) {
- // How many "push %reg" instructions are there at __kernel_vsyscall?
- // This is constant for a given kernel and processor, so compute
- // it only once.
- static int num_push_instructions = -1; // Sentinel: not computed yet.
- // Initialize with sentinel value: __kernel_rt_sigreturn can not possibly
- // be there.
- static const unsigned char *kernel_rt_sigreturn_address = NULL;
- static const unsigned char *kernel_vsyscall_address = NULL;
- if (num_push_instructions == -1) {
- base::VDSOSupport vdso;
- if (vdso.IsPresent()) {
- base::VDSOSupport::SymbolInfo rt_sigreturn_symbol_info;
- base::VDSOSupport::SymbolInfo vsyscall_symbol_info;
- if (!vdso.LookupSymbol("__kernel_rt_sigreturn", "LINUX_2.5",
- STT_FUNC, &rt_sigreturn_symbol_info) ||
- !vdso.LookupSymbol("__kernel_vsyscall", "LINUX_2.5",
- STT_FUNC, &vsyscall_symbol_info) ||
- rt_sigreturn_symbol_info.address == NULL ||
- vsyscall_symbol_info.address == NULL) {
- // Unexpected: 32-bit VDSO is present, yet one of the expected
- // symbols is missing or NULL.
- assert(0 == "VDSO is present, but doesn't have expected symbols");
- num_push_instructions = 0;
- } else {
- kernel_rt_sigreturn_address =
- reinterpret_cast<const unsigned char *>(
- rt_sigreturn_symbol_info.address);
- kernel_vsyscall_address =
- reinterpret_cast<const unsigned char *>(
- vsyscall_symbol_info.address);
- num_push_instructions =
- CountPushInstructions(kernel_vsyscall_address);
- }
- } else {
- num_push_instructions = 0;
- }
- }
- if (num_push_instructions != 0 && kernel_rt_sigreturn_address != NULL &&
- old_sp[1] == kernel_rt_sigreturn_address) {
- const ucontext_t *ucv = static_cast<const ucontext_t *>(uc);
- // This kernel does not use frame pointer in its VDSO code,
- // and so %ebp is not suitable for unwinding.
- void **const reg_ebp =
- reinterpret_cast<void **>(ucv->uc_mcontext.gregs[REG_EBP]);
- const unsigned char *const reg_eip =
- reinterpret_cast<unsigned char *>(ucv->uc_mcontext.gregs[REG_EIP]);
- if (new_sp == reg_ebp &&
- kernel_vsyscall_address <= reg_eip &&
- reg_eip - kernel_vsyscall_address < kMaxBytes) {
- // We "stepped up" to __kernel_vsyscall, but %ebp is not usable.
- // Restore from 'ucv' instead.
- void **const reg_esp =
- reinterpret_cast<void **>(ucv->uc_mcontext.gregs[REG_ESP]);
- // Check that alleged %esp is not NULL and is reasonably aligned.
- if (reg_esp &&
- ((uintptr_t)reg_esp & (sizeof(reg_esp) - 1)) == 0) {
- // Check that alleged %esp is actually readable. This is to prevent
- // "double fault" in case we hit the first fault due to e.g. stack
- // corruption.
- //
- // page_size is linker-initalized to avoid async-unsafe locking
- // that GCC would otherwise insert (__cxa_guard_acquire etc).
- static int page_size;
- if (page_size == 0) {
- // First time through.
- page_size = getpagesize();
- }
- void *const reg_esp_aligned =
- reinterpret_cast<void *>(
- (uintptr_t)(reg_esp + num_push_instructions - 1) &
- ~(page_size - 1));
- if (msync(reg_esp_aligned, page_size, MS_ASYNC) == 0) {
- // Alleged %esp is readable, use it for further unwinding.
- new_sp = reinterpret_cast<void **>(
- reg_esp[num_push_instructions - 1]);
- }
- }
- }
- }
- }
-#endif
-
- // Check that the transition from frame pointer old_sp to frame
- // pointer new_sp isn't clearly bogus
- if (STRICT_UNWINDING) {
- // With the stack growing downwards, older stack frame must be
- // at a greater address that the current one.
- if (new_sp <= old_sp) return NULL;
- // Assume stack frames larger than 100,000 bytes are bogus.
- if ((uintptr_t)new_sp - (uintptr_t)old_sp > 100000) return NULL;
- } else {
- // In the non-strict mode, allow discontiguous stack frames.
- // (alternate-signal-stacks for example).
- if (new_sp == old_sp) return NULL;
- if (new_sp > old_sp) {
- // And allow frames upto about 1MB.
- const uintptr_t delta = (uintptr_t)new_sp - (uintptr_t)old_sp;
- const uintptr_t acceptable_delta = 1000000;
- if (delta > acceptable_delta) {
- return NULL;
- }
- }
- }
- if ((uintptr_t)new_sp & (sizeof(void *) - 1)) return NULL;
-#ifdef __i386__
- // On 64-bit machines, the stack pointer can be very close to
- // 0xffffffff, so we explicitly check for a pointer into the
- // last two pages in the address space
- if ((uintptr_t)new_sp >= 0xffffe000) return NULL;
-#endif
-#ifdef HAVE_MMAP
- if (!STRICT_UNWINDING) {
- // Lax sanity checks cause a crash on AMD-based machines with
- // VDSO-enabled kernels.
- // Make an extra sanity check to insure new_sp is readable.
- // Note: NextStackFrame<false>() is only called while the program
- // is already on its last leg, so it's ok to be slow here.
- static int page_size = getpagesize();
- void *new_sp_aligned = (void *)((uintptr_t)new_sp & ~(page_size - 1));
- if (msync(new_sp_aligned, page_size, MS_ASYNC) == -1)
- return NULL;
- }
-#endif
- return new_sp;
-}
-
-#endif // BASE_STACKTRACE_X86_INL_H_
-
-// Note: this part of the file is included several times.
-// Do not put globals below.
-
-// The following 4 functions are generated from the code below:
-// GetStack{Trace,Frames}()
-// GetStack{Trace,Frames}WithContext()
-//
-// These functions take the following args:
-// void** result: the stack-trace, as an array
-// int* sizes: the size of each stack frame, as an array
-// (GetStackFrames* only)
-// int max_depth: the size of the result (and sizes) array(s)
-// int skip_count: how many stack pointers to skip before storing in result
-// void* ucp: a ucontext_t* (GetStack{Trace,Frames}WithContext only)
-
-static int GET_STACK_TRACE_OR_FRAMES {
- void **sp;
-#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) || __llvm__
- // __builtin_frame_address(0) can return the wrong address on gcc-4.1.0-k8.
- // It's always correct on llvm, and the techniques below aren't (in
- // particular, llvm-gcc will make a copy of pcs, so it's not in sp[2]),
- // so we also prefer __builtin_frame_address when running under llvm.
- sp = reinterpret_cast<void**>(__builtin_frame_address(0));
-#elif defined(__i386__)
- // Stack frame format:
- // sp[0] pointer to previous frame
- // sp[1] caller address
- // sp[2] first argument
- // ...
- // NOTE: This will break under llvm, since result is a copy and not in sp[2]
- sp = (void **)&result - 2;
-#elif defined(__x86_64__)
- unsigned long rbp;
- // Move the value of the register %rbp into the local variable rbp.
- // We need 'volatile' to prevent this instruction from getting moved
- // around during optimization to before function prologue is done.
- // An alternative way to achieve this
- // would be (before this __asm__ instruction) to call Noop() defined as
- // static void Noop() __attribute__ ((noinline)); // prevent inlining
- // static void Noop() { asm(""); } // prevent optimizing-away
- __asm__ volatile ("mov %%rbp, %0" : "=r" (rbp));
- // Arguments are passed in registers on x86-64, so we can't just
- // offset from &result
- sp = (void **) rbp;
-#else
-# error Using stacktrace_x86-inl.h on a non x86 architecture!
-#endif
-
- skip_count++; // skip parent's frame due to indirection in stacktrace.cc
-
- int n = 0;
- while (sp && n < max_depth) {
- if (*(sp+1) == reinterpret_cast<void *>(0)) {
- // In 64-bit code, we often see a frame that
- // points to itself and has a return address of 0.
- break;
- }
-#if !IS_WITH_CONTEXT
- const void *const ucp = NULL;
-#endif
- void **next_sp = NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(sp, ucp);
- if (skip_count > 0) {
- skip_count--;
- } else {
- result[n] = *(sp+1);
-#if IS_STACK_FRAMES
- if (next_sp > sp) {
- sizes[n] = (uintptr_t)next_sp - (uintptr_t)sp;
- } else {
- // A frame-size of 0 is used to indicate unknown frame size.
- sizes[n] = 0;
- }
-#endif
- n++;
- }
- sp = next_sp;
- }
- return n;
-}
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/static_vars.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/static_vars.cc b/third_party/gperftools/src/static_vars.cc
deleted file mode 100644
index 197b3a1..0000000
--- a/third_party/gperftools/src/static_vars.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2008, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Ken Ashcraft <op...@google.com>
-
-#include <config.h>
-#include "static_vars.h"
-#include <stddef.h> // for NULL
-#include <new> // for operator new
-#ifdef HAVE_PTHREAD
-#include <pthread.h> // for pthread_atfork
-#endif
-#include "internal_logging.h" // for CHECK_CONDITION
-#include "common.h"
-#include "sampler.h" // for Sampler
-#include "getenv_safe.h" // TCMallocGetenvSafe
-#include "base/googleinit.h"
-
-namespace tcmalloc {
-
-#if defined(HAVE_FORK) && defined(HAVE_PTHREAD)
-// These following two functions are registered via pthread_atfork to make
-// sure the central_cache locks remain in a consisten state in the forked
-// version of the thread.
-
-static
-void CentralCacheLockAll()
-{
- Static::pageheap_lock()->Lock();
- for (int i = 0; i < kNumClasses; ++i)
- Static::central_cache()[i].Lock();
-}
-
-static
-void CentralCacheUnlockAll()
-{
- for (int i = 0; i < kNumClasses; ++i)
- Static::central_cache()[i].Unlock();
- Static::pageheap_lock()->Unlock();
-}
-#endif
-
-SpinLock Static::pageheap_lock_(SpinLock::LINKER_INITIALIZED);
-SizeMap Static::sizemap_;
-CentralFreeListPadded Static::central_cache_[kNumClasses];
-PageHeapAllocator<Span> Static::span_allocator_;
-PageHeapAllocator<StackTrace> Static::stacktrace_allocator_;
-Span Static::sampled_objects_;
-PageHeapAllocator<StackTraceTable::Bucket> Static::bucket_allocator_;
-StackTrace* Static::growth_stacks_ = NULL;
-PageHeap* Static::pageheap_ = NULL;
-
-
-void Static::InitStaticVars() {
- sizemap_.Init();
- span_allocator_.Init();
- span_allocator_.New(); // Reduce cache conflicts
- span_allocator_.New(); // Reduce cache conflicts
- stacktrace_allocator_.Init();
- bucket_allocator_.Init();
- // Do a bit of sanitizing: make sure central_cache is aligned properly
- CHECK_CONDITION((sizeof(central_cache_[0]) % 64) == 0);
- for (int i = 0; i < kNumClasses; ++i) {
- central_cache_[i].Init(i);
- }
-
- // It's important to have PageHeap allocated, not in static storage,
- // so that HeapLeakChecker does not consider all the byte patterns stored
- // in is caches as pointers that are sources of heap object liveness,
- // which leads to it missing some memory leaks.
- pageheap_ = new (MetaDataAlloc(sizeof(PageHeap))) PageHeap;
-
- bool aggressive_decommit =
- tcmalloc::commandlineflags::StringToBool(
- TCMallocGetenvSafe("TCMALLOC_AGGRESSIVE_DECOMMIT"), true);
-
- pageheap_->SetAggressiveDecommit(aggressive_decommit);
-
- DLL_Init(&sampled_objects_);
- Sampler::InitStatics();
-}
-
-
-#if defined(HAVE_FORK) && defined(HAVE_PTHREAD)
-
-static inline
-void SetupAtForkLocksHandler()
-{
- pthread_atfork(CentralCacheLockAll, // parent calls before fork
- CentralCacheUnlockAll, // parent calls after fork
- CentralCacheUnlockAll); // child calls after fork
-}
-REGISTER_MODULE_INITIALIZER(tcmalloc_fork_handler, SetupAtForkLocksHandler());
-
-#endif
-
-} // namespace tcmalloc
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/static_vars.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/static_vars.h b/third_party/gperftools/src/static_vars.h
deleted file mode 100644
index c662e40..0000000
--- a/third_party/gperftools/src/static_vars.h
+++ /dev/null
@@ -1,115 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2008, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Ken Ashcraft <op...@google.com>
-//
-// Static variables shared by multiple classes.
-
-#ifndef TCMALLOC_STATIC_VARS_H_
-#define TCMALLOC_STATIC_VARS_H_
-
-#include <config.h>
-#include "base/spinlock.h"
-#include "central_freelist.h"
-#include "common.h"
-#include "page_heap.h"
-#include "page_heap_allocator.h"
-#include "span.h"
-#include "stack_trace_table.h"
-
-namespace tcmalloc {
-
-class Static {
- public:
- // Linker initialized, so this lock can be accessed at any time.
- static SpinLock* pageheap_lock() { return &pageheap_lock_; }
-
- // Must be called before calling any of the accessors below.
- static void InitStaticVars();
-
- // Central cache -- an array of free-lists, one per size-class.
- // We have a separate lock per free-list to reduce contention.
- static CentralFreeListPadded* central_cache() { return central_cache_; }
-
- static SizeMap* sizemap() { return &sizemap_; }
-
- //////////////////////////////////////////////////////////////////////
- // In addition to the explicit initialization comment, the variables below
- // must be protected by pageheap_lock.
-
- // Page-level allocator.
- static PageHeap* pageheap() { return pageheap_; }
-
- static PageHeapAllocator<Span>* span_allocator() { return &span_allocator_; }
-
- static PageHeapAllocator<StackTrace>* stacktrace_allocator() {
- return &stacktrace_allocator_;
- }
-
- static StackTrace* growth_stacks() { return growth_stacks_; }
- static void set_growth_stacks(StackTrace* s) { growth_stacks_ = s; }
-
- // State kept for sampled allocations (/pprof/heap support)
- static Span* sampled_objects() { return &sampled_objects_; }
- static PageHeapAllocator<StackTraceTable::Bucket>* bucket_allocator() {
- return &bucket_allocator_;
- }
-
- // Check if InitStaticVars() has been run.
- static bool IsInited() { return pageheap() != NULL; }
-
- private:
- static SpinLock pageheap_lock_;
-
- // These static variables require explicit initialization. We cannot
- // count on their constructors to do any initialization because other
- // static variables may try to allocate memory before these variables
- // can run their constructors.
-
- static SizeMap sizemap_;
- static CentralFreeListPadded central_cache_[kNumClasses];
- static PageHeapAllocator<Span> span_allocator_;
- static PageHeapAllocator<StackTrace> stacktrace_allocator_;
- static Span sampled_objects_;
- static PageHeapAllocator<StackTraceTable::Bucket> bucket_allocator_;
-
- // Linked list of stack traces recorded every time we allocated memory
- // from the system. Useful for finding allocation sites that cause
- // increase in the footprint of the system. The linked list pointer
- // is stored in trace->stack[kMaxStackDepth-1].
- static StackTrace* growth_stacks_;
-
- static PageHeap* pageheap_;
-};
-
-} // namespace tcmalloc
-
-#endif // TCMALLOC_STATIC_VARS_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/symbolize.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/symbolize.cc b/third_party/gperftools/src/symbolize.cc
deleted file mode 100755
index a27106e..0000000
--- a/third_party/gperftools/src/symbolize.cc
+++ /dev/null
@@ -1,285 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2009, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Craig Silverstein
-//
-// This forks out to pprof to do the actual symbolizing. We might
-// be better off writing our own in C++.
-
-#include "config.h"
-#include "symbolize.h"
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h> // for write()
-#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h> // for socketpair() -- needed by Symbolize
-#endif
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h> // for wait() -- needed by Symbolize
-#endif
-#ifdef HAVE_POLL_H
-#include <poll.h>
-#endif
-#ifdef __MACH__
-#include <mach-o/dyld.h> // for GetProgramInvocationName()
-#include <limits.h> // for PATH_MAX
-#endif
-#if defined(__CYGWIN__) || defined(__CYGWIN32__)
-#include <io.h> // for get_osfhandle()
-#endif
-#include <string>
-#include "base/commandlineflags.h"
-#include "base/logging.h"
-#include "base/sysinfo.h"
-
-using std::string;
-using tcmalloc::DumpProcSelfMaps; // from sysinfo.h
-
-
-DEFINE_string(symbolize_pprof,
- EnvToString("PPROF_PATH", "pprof"),
- "Path to pprof to call for reporting function names.");
-
-// heap_profile_table_pprof may be referenced after destructors are
-// called (since that's when leak-checking is done), so we make
-// a more-permanent copy that won't ever get destroyed.
-static string* g_pprof_path = new string(FLAGS_symbolize_pprof);
-
-// Returns NULL if we're on an OS where we can't get the invocation name.
-// Using a static var is ok because we're not called from a thread.
-static const char* GetProgramInvocationName() {
-#if defined(HAVE_PROGRAM_INVOCATION_NAME)
-#ifdef __UCLIBC__
- extern const char* program_invocation_name; // uclibc provides this
-#else
- extern char* program_invocation_name; // gcc provides this
-#endif
- return program_invocation_name;
-#elif defined(__MACH__)
- // We don't want to allocate memory for this since we may be
- // calculating it when memory is corrupted.
- static char program_invocation_name[PATH_MAX];
- if (program_invocation_name[0] == '\0') { // first time calculating
- uint32_t length = sizeof(program_invocation_name);
- if (_NSGetExecutablePath(program_invocation_name, &length))
- return NULL;
- }
- return program_invocation_name;
-#else
- return NULL; // figure out a way to get argv[0]
-#endif
-}
-
-// Prints an error message when you can't run Symbolize().
-static void PrintError(const char* reason) {
- RAW_LOG(ERROR,
- "*** WARNING: Cannot convert addresses to symbols in output below.\n"
- "*** Reason: %s\n"
- "*** If you cannot fix this, try running pprof directly.\n",
- reason);
-}
-
-void SymbolTable::Add(const void* addr) {
- symbolization_table_[addr] = "";
-}
-
-const char* SymbolTable::GetSymbol(const void* addr) {
- return symbolization_table_[addr];
-}
-
-// Updates symbolization_table with the pointers to symbol names corresponding
-// to its keys. The symbol names are stored in out, which is allocated and
-// freed by the caller of this routine.
-// Note that the forking/etc is not thread-safe or re-entrant. That's
-// ok for the purpose we need -- reporting leaks detected by heap-checker
-// -- but be careful if you decide to use this routine for other purposes.
-// Returns number of symbols read on error. If can't symbolize, returns 0
-// and emits an error message about why.
-int SymbolTable::Symbolize() {
-#if !defined(HAVE_UNISTD_H) || !defined(HAVE_SYS_SOCKET_H) || !defined(HAVE_SYS_WAIT_H)
- PrintError("Perftools does not know how to call a sub-process on this O/S");
- return 0;
-#else
- const char* argv0 = GetProgramInvocationName();
- if (argv0 == NULL) { // can't call symbolize if we can't figure out our name
- PrintError("Cannot figure out the name of this executable (argv0)");
- return 0;
- }
- if (access(g_pprof_path->c_str(), R_OK) != 0) {
- PrintError("Cannot find 'pprof' (is PPROF_PATH set correctly?)");
- return 0;
- }
-
- // All this work is to do two-way communication. ugh.
- int *child_in = NULL; // file descriptors
- int *child_out = NULL; // for now, we don't worry about child_err
- int child_fds[5][2]; // socketpair may be called up to five times below
-
- // The client program may close its stdin and/or stdout and/or stderr
- // thus allowing socketpair to reuse file descriptors 0, 1 or 2.
- // In this case the communication between the forked processes may be broken
- // if either the parent or the child tries to close or duplicate these
- // descriptors. The loop below produces two pairs of file descriptors, each
- // greater than 2 (stderr).
- for (int i = 0; i < 5; i++) {
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, child_fds[i]) == -1) {
- for (int j = 0; j < i; j++) {
- close(child_fds[j][0]);
- close(child_fds[j][1]);
- PrintError("Cannot create a socket pair");
- }
- return 0;
- } else {
- if ((child_fds[i][0] > 2) && (child_fds[i][1] > 2)) {
- if (child_in == NULL) {
- child_in = child_fds[i];
- } else {
- child_out = child_fds[i];
- for (int j = 0; j < i; j++) {
- if (child_fds[j] == child_in) continue;
- close(child_fds[j][0]);
- close(child_fds[j][1]);
- }
- break;
- }
- }
- }
- }
-
- switch (fork()) {
- case -1: { // error
- close(child_in[0]);
- close(child_in[1]);
- close(child_out[0]);
- close(child_out[1]);
- PrintError("Unknown error calling fork()");
- return 0;
- }
- case 0: { // child
- close(child_in[1]); // child uses the 0's, parent uses the 1's
- close(child_out[1]); // child uses the 0's, parent uses the 1's
- close(0);
- close(1);
- if (dup2(child_in[0], 0) == -1) _exit(1);
- if (dup2(child_out[0], 1) == -1) _exit(2);
- // Unset vars that might cause trouble when we fork
- unsetenv("CPUPROFILE");
- unsetenv("HEAPPROFILE");
- unsetenv("HEAPCHECK");
- unsetenv("PERFTOOLS_VERBOSE");
- execlp(g_pprof_path->c_str(), g_pprof_path->c_str(),
- "--symbols", argv0, NULL);
- _exit(3); // if execvp fails, it's bad news for us
- }
- default: { // parent
- close(child_in[0]); // child uses the 0's, parent uses the 1's
- close(child_out[0]); // child uses the 0's, parent uses the 1's
-#ifdef HAVE_POLL_H
- // Waiting for 1ms seems to give the OS time to notice any errors.
- poll(0, 0, 1);
- // For maximum safety, we check to make sure the execlp
- // succeeded before trying to write. (Otherwise we'll get a
- // SIGPIPE.) For systems without poll.h, we'll just skip this
- // check, and trust that the user set PPROF_PATH correctly!
- struct pollfd pfd = { child_in[1], POLLOUT, 0 };
- if (!poll(&pfd, 1, 0) || !(pfd.revents & POLLOUT) ||
- (pfd.revents & (POLLHUP|POLLERR))) {
- PrintError("Cannot run 'pprof' (is PPROF_PATH set correctly?)");
- return 0;
- }
-#endif
-#if defined(__CYGWIN__) || defined(__CYGWIN32__)
- // On cygwin, DumpProcSelfMaps() takes a HANDLE, not an fd. Convert.
- const HANDLE symbols_handle = (HANDLE) get_osfhandle(child_in[1]);
- DumpProcSelfMaps(symbols_handle);
-#else
- DumpProcSelfMaps(child_in[1]); // what pprof expects on stdin
-#endif
-
- // Allocate 24 bytes = ("0x" + 8 bytes + "\n" + overhead) for each
- // address to feed to pprof.
- const int kOutBufSize = 24 * symbolization_table_.size();
- char *pprof_buffer = new char[kOutBufSize];
- int written = 0;
- for (SymbolMap::const_iterator iter = symbolization_table_.begin();
- iter != symbolization_table_.end(); ++iter) {
- written += snprintf(pprof_buffer + written, kOutBufSize - written,
- // pprof expects format to be 0xXXXXXX
- "0x%" PRIxPTR "\n", reinterpret_cast<uintptr_t>(iter->first));
- }
- write(child_in[1], pprof_buffer, strlen(pprof_buffer));
- close(child_in[1]); // that's all we need to write
-
- const int kSymbolBufferSize = kSymbolSize * symbolization_table_.size();
- int total_bytes_read = 0;
- delete[] symbol_buffer_;
- symbol_buffer_ = new char[kSymbolBufferSize];
- memset(symbol_buffer_, '\0', kSymbolBufferSize);
- while (1) {
- int bytes_read = read(child_out[1], symbol_buffer_ + total_bytes_read,
- kSymbolBufferSize - total_bytes_read);
- if (bytes_read < 0) {
- close(child_out[1]);
- PrintError("Cannot read data from pprof");
- return 0;
- } else if (bytes_read == 0) {
- close(child_out[1]);
- wait(NULL);
- break;
- } else {
- total_bytes_read += bytes_read;
- }
- }
- // We have successfully read the output of pprof into out. Make sure
- // the last symbol is full (we can tell because it ends with a \n).
- if (total_bytes_read == 0 || symbol_buffer_[total_bytes_read - 1] != '\n')
- return 0;
- // make the symbolization_table_ values point to the output vector
- SymbolMap::iterator fill = symbolization_table_.begin();
- int num_symbols = 0;
- const char *current_name = symbol_buffer_;
- for (int i = 0; i < total_bytes_read; i++) {
- if (symbol_buffer_[i] == '\n') {
- fill->second = current_name;
- symbol_buffer_[i] = '\0';
- current_name = symbol_buffer_ + i + 1;
- fill++;
- num_symbols++;
- }
- }
- return num_symbols;
- }
- }
- PrintError("Unkown error (should never occur!)");
- return 0; // shouldn't be reachable
-#endif
-}
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/symbolize.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/symbolize.h b/third_party/gperftools/src/symbolize.h
deleted file mode 100644
index 728d073..0000000
--- a/third_party/gperftools/src/symbolize.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2009, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Craig Silverstein
-
-#ifndef TCMALLOC_SYMBOLIZE_H_
-#define TCMALLOC_SYMBOLIZE_H_
-
-#include "config.h"
-#ifdef HAVE_STDINT_H
-#include <stdint.h> // for uintptr_t
-#endif
-#include <stddef.h> // for NULL
-#include <map>
-
-using std::map;
-
-// SymbolTable encapsulates the address operations necessary for stack trace
-// symbolization. A common use-case is to Add() the addresses from one or
-// several stack traces to a table, call Symbolize() once and use GetSymbol()
-// to get the symbol names for pretty-printing the stack traces.
-class SymbolTable {
- public:
- SymbolTable()
- : symbol_buffer_(NULL) {}
- ~SymbolTable() {
- delete[] symbol_buffer_;
- }
-
- // Adds an address to the table. This may overwrite a currently known symbol
- // name, so Add() should not generally be called after Symbolize().
- void Add(const void* addr);
-
- // Returns the symbol name for addr, if the given address was added before
- // the last successful call to Symbolize(). Otherwise may return an empty
- // c-string.
- const char* GetSymbol(const void* addr);
-
- // Obtains the symbol names for the addresses stored in the table and returns
- // the number of addresses actually symbolized.
- int Symbolize();
-
- private:
- typedef map<const void*, const char*> SymbolMap;
-
- // An average size of memory allocated for a stack trace symbol.
- static const int kSymbolSize = 1024;
-
- // Map from addresses to symbol names.
- SymbolMap symbolization_table_;
-
- // Pointer to the buffer that stores the symbol names.
- char *symbol_buffer_;
-};
-
-#endif // TCMALLOC_SYMBOLIZE_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/system-alloc.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/system-alloc.cc b/third_party/gperftools/src/system-alloc.cc
deleted file mode 100755
index e61c087..0000000
--- a/third_party/gperftools/src/system-alloc.cc
+++ /dev/null
@@ -1,552 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-
-#include <config.h>
-#include <errno.h> // for EAGAIN, errno
-#include <fcntl.h> // for open, O_RDWR
-#include <stddef.h> // for size_t, NULL, ptrdiff_t
-#if defined HAVE_STDINT_H
-#include <stdint.h> // for uintptr_t, intptr_t
-#elif defined HAVE_INTTYPES_H
-#include <inttypes.h>
-#else
-#include <sys/types.h>
-#endif
-#ifdef HAVE_MMAP
-#include <sys/mman.h> // for munmap, mmap, MADV_DONTNEED, etc
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h> // for sbrk, getpagesize, off_t
-#endif
-#include <new> // for operator new
-#include <gperftools/malloc_extension.h>
-#include "base/basictypes.h"
-#include "base/commandlineflags.h"
-#include "base/spinlock.h" // for SpinLockHolder, SpinLock, etc
-#include "common.h"
-#include "internal_logging.h"
-
-// On systems (like freebsd) that don't define MAP_ANONYMOUS, use the old
-// form of the name instead.
-#ifndef MAP_ANONYMOUS
-# define MAP_ANONYMOUS MAP_ANON
-#endif
-
-// MADV_FREE is specifically designed for use by malloc(), but only
-// FreeBSD supports it; in linux we fall back to the somewhat inferior
-// MADV_DONTNEED.
-#if !defined(MADV_FREE) && defined(MADV_DONTNEED)
-# define MADV_FREE MADV_DONTNEED
-#endif
-
-// Solaris has a bug where it doesn't declare madvise() for C++.
-// http://www.opensolaris.org/jive/thread.jspa?threadID=21035&tstart=0
-#if defined(__sun) && defined(__SVR4)
-# include <sys/types.h> // for caddr_t
- extern "C" { extern int madvise(caddr_t, size_t, int); }
-#endif
-
-// Set kDebugMode mode so that we can have use C++ conditionals
-// instead of preprocessor conditionals.
-#ifdef NDEBUG
-static const bool kDebugMode = false;
-#else
-static const bool kDebugMode = true;
-#endif
-
-// TODO(sanjay): Move the code below into the tcmalloc namespace
-using tcmalloc::kLog;
-using tcmalloc::Log;
-
-// Anonymous namespace to avoid name conflicts on "CheckAddressBits".
-namespace {
-
-// Check that no bit is set at position ADDRESS_BITS or higher.
-template <int ADDRESS_BITS> bool CheckAddressBits(uintptr_t ptr) {
- return (ptr >> ADDRESS_BITS) == 0;
-}
-
-// Specialize for the bit width of a pointer to avoid undefined shift.
-template <> bool CheckAddressBits<8 * sizeof(void*)>(uintptr_t ptr) {
- return true;
-}
-
-} // Anonymous namespace to avoid name conflicts on "CheckAddressBits".
-
-COMPILE_ASSERT(kAddressBits <= 8 * sizeof(void*),
- address_bits_larger_than_pointer_size);
-
-// Structure for discovering alignment
-union MemoryAligner {
- void* p;
- double d;
- size_t s;
-} CACHELINE_ALIGNED;
-
-static SpinLock spinlock(SpinLock::LINKER_INITIALIZED);
-
-#if defined(HAVE_MMAP) || defined(MADV_FREE)
-// Page size is initialized on demand (only needed for mmap-based allocators)
-static size_t pagesize = 0;
-#endif
-
-// The current system allocator
-SysAllocator* sys_alloc = NULL;
-
-// Number of bytes taken from system.
-size_t TCMalloc_SystemTaken = 0;
-
-// Configuration parameters.
-DEFINE_int32(malloc_devmem_start,
- EnvToInt("TCMALLOC_DEVMEM_START", 0),
- "Physical memory starting location in MB for /dev/mem allocation."
- " Setting this to 0 disables /dev/mem allocation");
-DEFINE_int32(malloc_devmem_limit,
- EnvToInt("TCMALLOC_DEVMEM_LIMIT", 0),
- "Physical memory limit location in MB for /dev/mem allocation."
- " Setting this to 0 means no limit.");
-DEFINE_bool(malloc_skip_sbrk,
- EnvToBool("TCMALLOC_SKIP_SBRK", false),
- "Whether sbrk can be used to obtain memory.");
-DEFINE_bool(malloc_skip_mmap,
- EnvToBool("TCMALLOC_SKIP_MMAP", false),
- "Whether mmap can be used to obtain memory.");
-DEFINE_bool(malloc_disable_memory_release,
- EnvToBool("TCMALLOC_DISABLE_MEMORY_RELEASE", false),
- "Whether MADV_FREE/MADV_DONTNEED should be used"
- " to return unused memory to the system.");
-
-// static allocators
-class SbrkSysAllocator : public SysAllocator {
-public:
- SbrkSysAllocator() : SysAllocator() {
- }
- void* Alloc(size_t size, size_t *actual_size, size_t alignment);
-};
-static char sbrk_space[sizeof(SbrkSysAllocator)];
-
-class MmapSysAllocator : public SysAllocator {
-public:
- MmapSysAllocator() : SysAllocator() {
- }
- void* Alloc(size_t size, size_t *actual_size, size_t alignment);
-};
-static char mmap_space[sizeof(MmapSysAllocator)];
-
-class DevMemSysAllocator : public SysAllocator {
-public:
- DevMemSysAllocator() : SysAllocator() {
- }
- void* Alloc(size_t size, size_t *actual_size, size_t alignment);
-};
-
-class DefaultSysAllocator : public SysAllocator {
- public:
- DefaultSysAllocator() : SysAllocator() {
- for (int i = 0; i < kMaxAllocators; i++) {
- failed_[i] = true;
- allocs_[i] = NULL;
- names_[i] = NULL;
- }
- }
- void SetChildAllocator(SysAllocator* alloc, unsigned int index,
- const char* name) {
- if (index < kMaxAllocators && alloc != NULL) {
- allocs_[index] = alloc;
- failed_[index] = false;
- names_[index] = name;
- }
- }
- void* Alloc(size_t size, size_t *actual_size, size_t alignment);
-
- private:
- static const int kMaxAllocators = 2;
- bool failed_[kMaxAllocators];
- SysAllocator* allocs_[kMaxAllocators];
- const char* names_[kMaxAllocators];
-};
-static char default_space[sizeof(DefaultSysAllocator)];
-static const char sbrk_name[] = "SbrkSysAllocator";
-static const char mmap_name[] = "MmapSysAllocator";
-
-
-void* SbrkSysAllocator::Alloc(size_t size, size_t *actual_size,
- size_t alignment) {
-#if !defined(HAVE_SBRK) || defined(__UCLIBC__)
- return NULL;
-#else
- // Check if we should use sbrk allocation.
- // FLAGS_malloc_skip_sbrk starts out as false (its uninitialized
- // state) and eventually gets initialized to the specified value. Note
- // that this code runs for a while before the flags are initialized.
- // That means that even if this flag is set to true, some (initial)
- // memory will be allocated with sbrk before the flag takes effect.
- if (FLAGS_malloc_skip_sbrk) {
- return NULL;
- }
-
- // sbrk will release memory if passed a negative number, so we do
- // a strict check here
- if (static_cast<ptrdiff_t>(size + alignment) < 0) return NULL;
-
- // This doesn't overflow because TCMalloc_SystemAlloc has already
- // tested for overflow at the alignment boundary.
- size = ((size + alignment - 1) / alignment) * alignment;
-
- // "actual_size" indicates that the bytes from the returned pointer
- // p up to and including (p + actual_size - 1) have been allocated.
- if (actual_size) {
- *actual_size = size;
- }
-
- // Check that we we're not asking for so much more memory that we'd
- // wrap around the end of the virtual address space. (This seems
- // like something sbrk() should check for us, and indeed opensolaris
- // does, but glibc does not:
- // http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/sys/sbrk.c?a=true
- // http://sourceware.org/cgi-bin/cvsweb.cgi/~checkout~/libc/misc/sbrk.c?rev=1.1.2.1&content-type=text/plain&cvsroot=glibc
- // Without this check, sbrk may succeed when it ought to fail.)
- if (reinterpret_cast<intptr_t>(sbrk(0)) + size < size) {
- return NULL;
- }
-
- void* result = sbrk(size);
- if (result == reinterpret_cast<void*>(-1)) {
- return NULL;
- }
-
- // Is it aligned?
- uintptr_t ptr = reinterpret_cast<uintptr_t>(result);
- if ((ptr & (alignment-1)) == 0) return result;
-
- // Try to get more memory for alignment
- size_t extra = alignment - (ptr & (alignment-1));
- void* r2 = sbrk(extra);
- if (reinterpret_cast<uintptr_t>(r2) == (ptr + size)) {
- // Contiguous with previous result
- return reinterpret_cast<void*>(ptr + extra);
- }
-
- // Give up and ask for "size + alignment - 1" bytes so
- // that we can find an aligned region within it.
- result = sbrk(size + alignment - 1);
- if (result == reinterpret_cast<void*>(-1)) {
- return NULL;
- }
- ptr = reinterpret_cast<uintptr_t>(result);
- if ((ptr & (alignment-1)) != 0) {
- ptr += alignment - (ptr & (alignment-1));
- }
- return reinterpret_cast<void*>(ptr);
-#endif // HAVE_SBRK
-}
-
-void* MmapSysAllocator::Alloc(size_t size, size_t *actual_size,
- size_t alignment) {
-#ifndef HAVE_MMAP
- return NULL;
-#else
- // Check if we should use mmap allocation.
- // FLAGS_malloc_skip_mmap starts out as false (its uninitialized
- // state) and eventually gets initialized to the specified value. Note
- // that this code runs for a while before the flags are initialized.
- // Chances are we never get here before the flags are initialized since
- // sbrk is used until the heap is exhausted (before mmap is used).
- if (FLAGS_malloc_skip_mmap) {
- return NULL;
- }
-
- // Enforce page alignment
- if (pagesize == 0) pagesize = getpagesize();
- if (alignment < pagesize) alignment = pagesize;
- size_t aligned_size = ((size + alignment - 1) / alignment) * alignment;
- if (aligned_size < size) {
- return NULL;
- }
- size = aligned_size;
-
- // "actual_size" indicates that the bytes from the returned pointer
- // p up to and including (p + actual_size - 1) have been allocated.
- if (actual_size) {
- *actual_size = size;
- }
-
- // Ask for extra memory if alignment > pagesize
- size_t extra = 0;
- if (alignment > pagesize) {
- extra = alignment - pagesize;
- }
-
- // Note: size + extra does not overflow since:
- // size + alignment < (1<<NBITS).
- // and extra <= alignment
- // therefore size + extra < (1<<NBITS)
- void* result = mmap(NULL, size + extra,
- PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS,
- -1, 0);
- if (result == reinterpret_cast<void*>(MAP_FAILED)) {
- return NULL;
- }
-
- // Adjust the return memory so it is aligned
- uintptr_t ptr = reinterpret_cast<uintptr_t>(result);
- size_t adjust = 0;
- if ((ptr & (alignment - 1)) != 0) {
- adjust = alignment - (ptr & (alignment - 1));
- }
-
- // Return the unused memory to the system
- if (adjust > 0) {
- munmap(reinterpret_cast<void*>(ptr), adjust);
- }
- if (adjust < extra) {
- munmap(reinterpret_cast<void*>(ptr + adjust + size), extra - adjust);
- }
-
- ptr += adjust;
- return reinterpret_cast<void*>(ptr);
-#endif // HAVE_MMAP
-}
-
-void* DevMemSysAllocator::Alloc(size_t size, size_t *actual_size,
- size_t alignment) {
-#ifndef HAVE_MMAP
- return NULL;
-#else
- static bool initialized = false;
- static off_t physmem_base; // next physical memory address to allocate
- static off_t physmem_limit; // maximum physical address allowed
- static int physmem_fd; // file descriptor for /dev/mem
-
- // Check if we should use /dev/mem allocation. Note that it may take
- // a while to get this flag initialized, so meanwhile we fall back to
- // the next allocator. (It looks like 7MB gets allocated before
- // this flag gets initialized -khr.)
- if (FLAGS_malloc_devmem_start == 0) {
- // NOTE: not a devmem_failure - we'd like TCMalloc_SystemAlloc to
- // try us again next time.
- return NULL;
- }
-
- if (!initialized) {
- physmem_fd = open("/dev/mem", O_RDWR);
- if (physmem_fd < 0) {
- return NULL;
- }
- physmem_base = FLAGS_malloc_devmem_start*1024LL*1024LL;
- physmem_limit = FLAGS_malloc_devmem_limit*1024LL*1024LL;
- initialized = true;
- }
-
- // Enforce page alignment
- if (pagesize == 0) pagesize = getpagesize();
- if (alignment < pagesize) alignment = pagesize;
- size_t aligned_size = ((size + alignment - 1) / alignment) * alignment;
- if (aligned_size < size) {
- return NULL;
- }
- size = aligned_size;
-
- // "actual_size" indicates that the bytes from the returned pointer
- // p up to and including (p + actual_size - 1) have been allocated.
- if (actual_size) {
- *actual_size = size;
- }
-
- // Ask for extra memory if alignment > pagesize
- size_t extra = 0;
- if (alignment > pagesize) {
- extra = alignment - pagesize;
- }
-
- // check to see if we have any memory left
- if (physmem_limit != 0 &&
- ((size + extra) > (physmem_limit - physmem_base))) {
- return NULL;
- }
-
- // Note: size + extra does not overflow since:
- // size + alignment < (1<<NBITS).
- // and extra <= alignment
- // therefore size + extra < (1<<NBITS)
- void *result = mmap(0, size + extra, PROT_WRITE|PROT_READ,
- MAP_SHARED, physmem_fd, physmem_base);
- if (result == reinterpret_cast<void*>(MAP_FAILED)) {
- return NULL;
- }
- uintptr_t ptr = reinterpret_cast<uintptr_t>(result);
-
- // Adjust the return memory so it is aligned
- size_t adjust = 0;
- if ((ptr & (alignment - 1)) != 0) {
- adjust = alignment - (ptr & (alignment - 1));
- }
-
- // Return the unused virtual memory to the system
- if (adjust > 0) {
- munmap(reinterpret_cast<void*>(ptr), adjust);
- }
- if (adjust < extra) {
- munmap(reinterpret_cast<void*>(ptr + adjust + size), extra - adjust);
- }
-
- ptr += adjust;
- physmem_base += adjust + size;
-
- return reinterpret_cast<void*>(ptr);
-#endif // HAVE_MMAP
-}
-
-void* DefaultSysAllocator::Alloc(size_t size, size_t *actual_size,
- size_t alignment) {
- for (int i = 0; i < kMaxAllocators; i++) {
- if (!failed_[i] && allocs_[i] != NULL) {
- void* result = allocs_[i]->Alloc(size, actual_size, alignment);
- if (result != NULL) {
- return result;
- }
- failed_[i] = true;
- }
- }
- // After both failed, reset "failed_" to false so that a single failed
- // allocation won't make the allocator never work again.
- for (int i = 0; i < kMaxAllocators; i++) {
- failed_[i] = false;
- }
- return NULL;
-}
-
-ATTRIBUTE_WEAK ATTRIBUTE_NOINLINE
-SysAllocator *tc_get_sysalloc_override(SysAllocator *def)
-{
- return def;
-}
-
-static bool system_alloc_inited = false;
-void InitSystemAllocators(void) {
- MmapSysAllocator *mmap = new (mmap_space) MmapSysAllocator();
- SbrkSysAllocator *sbrk = new (sbrk_space) SbrkSysAllocator();
-
- // In 64-bit debug mode, place the mmap allocator first since it
- // allocates pointers that do not fit in 32 bits and therefore gives
- // us better testing of code's 64-bit correctness. It also leads to
- // less false negatives in heap-checking code. (Numbers are less
- // likely to look like pointers and therefore the conservative gc in
- // the heap-checker is less likely to misinterpret a number as a
- // pointer).
- DefaultSysAllocator *sdef = new (default_space) DefaultSysAllocator();
- if (kDebugMode && sizeof(void*) > 4) {
- sdef->SetChildAllocator(mmap, 0, mmap_name);
- sdef->SetChildAllocator(sbrk, 1, sbrk_name);
- } else {
- sdef->SetChildAllocator(sbrk, 0, sbrk_name);
- sdef->SetChildAllocator(mmap, 1, mmap_name);
- }
-
- sys_alloc = tc_get_sysalloc_override(sdef);
-}
-
-void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
- size_t alignment) {
- // Discard requests that overflow
- if (size + alignment < size) return NULL;
-
- SpinLockHolder lock_holder(&spinlock);
-
- if (!system_alloc_inited) {
- InitSystemAllocators();
- system_alloc_inited = true;
- }
-
- // Enforce minimum alignment
- if (alignment < sizeof(MemoryAligner)) alignment = sizeof(MemoryAligner);
-
- size_t actual_size_storage;
- if (actual_size == NULL) {
- actual_size = &actual_size_storage;
- }
-
- void* result = sys_alloc->Alloc(size, actual_size, alignment);
- if (result != NULL) {
- CHECK_CONDITION(
- CheckAddressBits<kAddressBits>(
- reinterpret_cast<uintptr_t>(result) + *actual_size - 1));
- TCMalloc_SystemTaken += *actual_size;
- }
- return result;
-}
-
-bool TCMalloc_SystemRelease(void* start, size_t length) {
-#ifdef MADV_FREE
- if (FLAGS_malloc_devmem_start) {
- // It's not safe to use MADV_FREE/MADV_DONTNEED if we've been
- // mapping /dev/mem for heap memory.
- return false;
- }
- if (FLAGS_malloc_disable_memory_release) return false;
- if (pagesize == 0) pagesize = getpagesize();
- const size_t pagemask = pagesize - 1;
-
- size_t new_start = reinterpret_cast<size_t>(start);
- size_t end = new_start + length;
- size_t new_end = end;
-
- // Round up the starting address and round down the ending address
- // to be page aligned:
- new_start = (new_start + pagesize - 1) & ~pagemask;
- new_end = new_end & ~pagemask;
-
- ASSERT((new_start & pagemask) == 0);
- ASSERT((new_end & pagemask) == 0);
- ASSERT(new_start >= reinterpret_cast<size_t>(start));
- ASSERT(new_end <= end);
-
- if (new_end > new_start) {
- int result;
- do {
- result = madvise(reinterpret_cast<char*>(new_start),
- new_end - new_start, MADV_FREE);
- } while (result == -1 && errno == EAGAIN);
-
- return result != -1;
- }
-#endif
- return false;
-}
-
-void TCMalloc_SystemCommit(void* start, size_t length) {
- // Nothing to do here. TCMalloc_SystemRelease does not alter pages
- // such that they need to be re-committed before they can be used by the
- // application.
-}
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/system-alloc.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/system-alloc.h b/third_party/gperftools/src/system-alloc.h
deleted file mode 100644
index 8233f96..0000000
--- a/third_party/gperftools/src/system-alloc.h
+++ /dev/null
@@ -1,92 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-//
-// Routine that uses sbrk/mmap to allocate memory from the system.
-// Useful for implementing malloc.
-
-#ifndef TCMALLOC_SYSTEM_ALLOC_H_
-#define TCMALLOC_SYSTEM_ALLOC_H_
-
-#include <config.h>
-#include <stddef.h> // for size_t
-
-class SysAllocator;
-
-// REQUIRES: "alignment" is a power of two or "0" to indicate default alignment
-//
-// Allocate and return "N" bytes of zeroed memory.
-//
-// If actual_bytes is NULL then the returned memory is exactly the
-// requested size. If actual bytes is non-NULL then the allocator
-// may optionally return more bytes than asked for (i.e. return an
-// entire "huge" page if a huge page allocator is in use).
-//
-// The returned pointer is a multiple of "alignment" if non-zero. The
-// returned pointer will always be aligned suitably for holding a
-// void*, double, or size_t. In addition, if this platform defines
-// CACHELINE_ALIGNED, the return pointer will always be cacheline
-// aligned.
-//
-// Returns NULL when out of memory.
-extern PERFTOOLS_DLL_DECL
-void* TCMalloc_SystemAlloc(size_t bytes, size_t *actual_bytes,
- size_t alignment = 0);
-
-// This call is a hint to the operating system that the pages
-// contained in the specified range of memory will not be used for a
-// while, and can be released for use by other processes or the OS.
-// Pages which are released in this way may be destroyed (zeroed) by
-// the OS. The benefit of this function is that it frees memory for
-// use by the system, the cost is that the pages are faulted back into
-// the address space next time they are touched, which can impact
-// performance. (Only pages fully covered by the memory region will
-// be released, partial pages will not.)
-//
-// Returns false if release failed or not supported.
-extern PERFTOOLS_DLL_DECL
-bool TCMalloc_SystemRelease(void* start, size_t length);
-
-// Called to ressurect memory which has been previously released
-// to the system via TCMalloc_SystemRelease. An attempt to
-// commit a page that is already committed does not cause this
-// function to fail.
-extern PERFTOOLS_DLL_DECL
-void TCMalloc_SystemCommit(void* start, size_t length);
-
-// The current system allocator.
-extern PERFTOOLS_DLL_DECL SysAllocator* sys_alloc;
-
-// Number of bytes taken from system.
-extern PERFTOOLS_DLL_DECL size_t TCMalloc_SystemTaken;
-
-#endif /* TCMALLOC_SYSTEM_ALLOC_H_ */