Gc.hx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C)2005-2017 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 Std.int(NativeGc.memInfo(inWhatInfo));
  51. }
  52. // Returns Float
  53. static public function memInfo64(inWhatInfo:Int) : Float
  54. {
  55. return NativeGc.memInfo(inWhatInfo);
  56. }
  57. static public function memUsage() : Int
  58. {
  59. return Std.int(NativeGc.memInfo(MEM_INFO_USAGE));
  60. }
  61. static public function trace(sought:Class<Dynamic>,printInstances:Bool=true) : Int
  62. {
  63. return untyped __global__.__hxcpp_gc_trace(sought,printInstances);
  64. }
  65. static public function versionCheck() { return true; }
  66. static public function doNotKill(inObject:Dynamic) : Void
  67. {
  68. untyped __global__.__hxcpp_gc_do_not_kill(inObject);
  69. }
  70. static public function getNextZombie() : Dynamic
  71. {
  72. return untyped __global__.__hxcpp_get_next_zombie();
  73. }
  74. static public function safePoint() : Void
  75. {
  76. untyped __global__.__hxcpp_gc_safe_point();
  77. }
  78. static public function enterGCFreeZone() : Void
  79. {
  80. untyped __global__.__hxcpp_enter_gc_free_zone();
  81. }
  82. static public function exitGCFreeZone() : Void
  83. {
  84. untyped __global__.__hxcpp_exit_gc_free_zone();
  85. }
  86. static public function setMinimumFreeSpace(inBytes:Int) : Void
  87. {
  88. untyped __global__.__hxcpp_set_minimum_free_space(inBytes);
  89. }
  90. static public function setTargetFreeSpacePercentage(inPercentage:Int) : Void
  91. {
  92. untyped __global__.__hxcpp_set_target_free_space_percentage(inPercentage);
  93. }
  94. static public function setMinimumWorkingMemory(inBytes:Int) : Void
  95. {
  96. untyped __global__.__hxcpp_set_minimum_working_memory(inBytes);
  97. }
  98. @:unreflective
  99. inline static public function setFinalizer<T>(inObject:T, inFinalizer:cpp.Callable<T->Void> ) : Void
  100. {
  101. untyped __global__.__hxcpp_set_finalizer(inObject, inFinalizer);
  102. }
  103. }