Gc.hx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // 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. static public function memInfo(inWhatInfo:Int) : Int
  37. {
  38. return Std.int(NativeGc.memInfo(inWhatInfo));
  39. }
  40. // Returns Float
  41. static public function memInfo64(inWhatInfo:Int) : Float
  42. {
  43. return NativeGc.memInfo(inWhatInfo);
  44. }
  45. static public function memUsage() : Int
  46. {
  47. return Std.int(NativeGc.memInfo(MEM_INFO_USAGE));
  48. }
  49. static public function versionCheck() { return true; }
  50. static public function trace(sought:Class<Dynamic>,printInstances:Bool=true) : Int
  51. {
  52. return cpp.NativeGc.nativeTrace(sought,printInstances);
  53. }
  54. #if !cppia inline #end
  55. static public function enable(inEnable:Bool) : Void
  56. cpp.NativeGc.enable(inEnable);
  57. #if !cppia inline #end
  58. static public function run(major:Bool) : Void
  59. cpp.NativeGc.run(major);
  60. #if !cppia inline #end
  61. static public function compact() : Void
  62. cpp.NativeGc.compact();
  63. #if !cppia inline #end
  64. static public function doNotKill(inObject:Dynamic) : Void
  65. cpp.NativeGc.doNotKill(inObject);
  66. #if !cppia inline #end
  67. static public function getNextZombie() : Dynamic
  68. return cpp.NativeGc.getNextZombie();
  69. #if !cppia inline #end
  70. static public function safePoint() : Void
  71. cpp.NativeGc.safePoint();
  72. #if !cppia inline #end
  73. static public function enterGCFreeZone() : Void
  74. cpp.NativeGc.enterGCFreeZone();
  75. #if !cppia inline #end
  76. static public function exitGCFreeZone() : Void
  77. cpp.NativeGc.exitGCFreeZone();
  78. #if !cppia inline #end
  79. static public function setMinimumFreeSpace(inBytes:Int) : Void
  80. cpp.NativeGc.setMinimumFreeSpace(inBytes);
  81. #if !cppia inline #end
  82. static public function setTargetFreeSpacePercentage(inPercentage:Int) : Void
  83. cpp.NativeGc.setTargetFreeSpacePercentage(inPercentage);
  84. #if !cppia inline #end
  85. static public function setMinimumWorkingMemory(inBytes:Int) : Void
  86. cpp.NativeGc.setMinimumWorkingMemory(inBytes);
  87. #if !cppia
  88. @:native("__hxcpp_set_finalizer") @:extern
  89. static public function setFinalizer<T>(inObject:T, inFinalizer:cpp.Callable<T->Void> ) : Void { }
  90. #end
  91. }