GCActivityCallbackBlackBerry.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "GCActivityCallback.h"
  20. #include "Heap.h"
  21. #include "VM.h"
  22. #include <BlackBerryPlatformMemory.h>
  23. namespace JSC {
  24. DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
  25. : GCActivityCallback(heap->vm())
  26. {
  27. }
  28. void DefaultGCActivityCallback::doWork()
  29. {
  30. JSLockHolder lock(m_vm);
  31. m_vm->heap.collect(Heap::DoNotSweep);
  32. }
  33. void DefaultGCActivityCallback::didAllocate(size_t)
  34. {
  35. if (m_timer.started())
  36. return;
  37. // Try using ~5% CPU time.
  38. m_timer.start(m_vm->heap.lastGCLength() * 20);
  39. }
  40. void DefaultGCActivityCallback::willCollect()
  41. {
  42. cancel();
  43. }
  44. void DefaultGCActivityCallback::cancel()
  45. {
  46. m_timer.stop();
  47. }
  48. }