Gc.hx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C)2005-2019 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. public static inline var MEM_INFO_USAGE = 0;
  25. public static inline var MEM_INFO_RESERVED = 1;
  26. public static inline var MEM_INFO_CURRENT = 2;
  27. public static inline var MEM_INFO_LARGE = 3;
  28. /**
  29. Introduced hxcpp_api_level 310
  30. Returns stats on memory usage:
  31. - `MEM_INFO_USAGE` - estimate of how much is needed by program (at last collect)
  32. - `MEM_INFO_RESERVED` - memory allocated for possible use
  33. - `MEM_INFO_CURRENT` - memory in use, includes uncollected garbage.
  34. This will generally saw-tooth between USAGE and RESERVED
  35. - `MEM_INFO_LARGE` - Size of separate pool used for large allocs. Included in all the above.
  36. **/
  37. static public function memInfo(inWhatInfo:Int):Int {
  38. return Std.int(NativeGc.memInfo(inWhatInfo));
  39. }
  40. // Returns Float
  41. static public function memInfo64(inWhatInfo:Int):Float {
  42. return NativeGc.memInfo(inWhatInfo);
  43. }
  44. static public function memUsage():Int {
  45. return Std.int(NativeGc.memInfo(MEM_INFO_USAGE));
  46. }
  47. static public function versionCheck() {
  48. return true;
  49. }
  50. static public function trace(sought:Class<Dynamic>, printInstances:Bool = true):Int {
  51. return cpp.NativeGc.nativeTrace(sought, printInstances);
  52. }
  53. #if !cppia
  54. inline
  55. #end
  56. static public function enable(inEnable:Bool):Void
  57. cpp.NativeGc.enable(inEnable);
  58. #if !cppia
  59. inline
  60. #end
  61. static public function run(major:Bool):Void
  62. cpp.NativeGc.run(major);
  63. #if !cppia
  64. inline
  65. #end
  66. static public function compact():Void
  67. cpp.NativeGc.compact();
  68. #if !cppia
  69. inline
  70. #end
  71. static public function doNotKill(inObject:Dynamic):Void
  72. cpp.NativeGc.doNotKill(inObject);
  73. #if !cppia
  74. inline
  75. #end
  76. static public function getNextZombie():Dynamic
  77. return cpp.NativeGc.getNextZombie();
  78. #if !cppia
  79. inline
  80. #end
  81. static public function safePoint():Void
  82. cpp.NativeGc.safePoint();
  83. #if !cppia
  84. inline
  85. #end
  86. static public function enterGCFreeZone():Void
  87. cpp.NativeGc.enterGCFreeZone();
  88. #if !cppia
  89. inline
  90. #end
  91. static public function exitGCFreeZone():Void
  92. cpp.NativeGc.exitGCFreeZone();
  93. #if !cppia
  94. inline
  95. #end
  96. static public function setMinimumFreeSpace(inBytes:Int):Void
  97. cpp.NativeGc.setMinimumFreeSpace(inBytes);
  98. #if !cppia
  99. inline
  100. #end
  101. static public function setTargetFreeSpacePercentage(inPercentage:Int):Void
  102. cpp.NativeGc.setTargetFreeSpacePercentage(inPercentage);
  103. #if !cppia
  104. inline
  105. #end
  106. static public function setMinimumWorkingMemory(inBytes:Int):Void
  107. cpp.NativeGc.setMinimumWorkingMemory(inBytes);
  108. #if !cppia
  109. @:native("__hxcpp_set_finalizer") extern static public function setFinalizer<T>(inObject:T, inFinalizer:cpp.Callable<T->Void>):Void;
  110. #end
  111. }