Gc.hx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C)2005-2012 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package cpp.vm;
  23. class Gc
  24. {
  25. public static inline var MEM_INFO_USAGE = 0;
  26. public static inline var MEM_INFO_RESERVED = 1;
  27. public static inline var MEM_INFO_CURRENT = 2;
  28. public static inline var MEM_INFO_LARGE = 3;
  29. static public function enable(inEnable:Bool) : Void
  30. {
  31. untyped __global__.__hxcpp_enable(inEnable);
  32. }
  33. static public function run(major:Bool) : Void
  34. {
  35. untyped __global__.__hxcpp_collect(major);
  36. }
  37. static public function compact() : Void
  38. {
  39. untyped __global__.__hxcpp_gc_compact();
  40. }
  41. // Introduced hxcpp_api_level 310
  42. // Returns stats on memory usage:
  43. // MEM_INFO_USAGE - estimate of how much is needed by program (at last collect)
  44. // MEM_INFO_RESERVED - memory allocated for possible use
  45. // MEM_INFO_CURRENT - memory in use, includes uncollected garbage.
  46. // This will generally saw-tooth between USAGE and RESERVED
  47. // MEM_INFO_LARGE - Size of separate pool used for large allocs. Included in all the above.
  48. static public function memInfo(inWhatInfo:Int) : Int
  49. {
  50. return untyped __global__.__hxcpp_gc_mem_info(inWhatInfo);
  51. }
  52. static public function memUsage() : Int
  53. {
  54. return untyped __global__.__hxcpp_gc_mem_info(MEM_INFO_USAGE);
  55. }
  56. static public function trace(sought:Class<Dynamic>,printInstances:Bool=true) : Int
  57. {
  58. return untyped __global__.__hxcpp_gc_trace(sought,printInstances);
  59. }
  60. static public function versionCheck() { return true; }
  61. static public function doNotKill(inObject:Dynamic) : Void
  62. {
  63. untyped __global__.__hxcpp_gc_do_not_kill(inObject);
  64. }
  65. static public function getNextZombie() : Dynamic
  66. {
  67. return untyped __global__.__hxcpp_get_next_zombie();
  68. }
  69. static public function safePoint() : Void
  70. {
  71. untyped __global__.__hxcpp_gc_safe_point();
  72. }
  73. static public function enterGCFreeZone() : Void
  74. {
  75. untyped __global__.__hxcpp_enter_gc_free_zone();
  76. }
  77. static public function exitGCFreeZone() : Void
  78. {
  79. untyped __global__.__hxcpp_exit_gc_free_zone();
  80. }
  81. @:unreflective
  82. inline static public function setFinalizer<T>(inObject:T, inFinalizer:cpp.Callable<T->Void> ) : Void
  83. {
  84. untyped __global__.__hxcpp_set_finalizer(inObject, inFinalizer);
  85. }
  86. }