forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
102
Kha/Backends/Kinc-hxcpp/khacpp/test/haxe/gc/TestBigStack.hx
Executable file
102
Kha/Backends/Kinc-hxcpp/khacpp/test/haxe/gc/TestBigStack.hx
Executable file
@ -0,0 +1,102 @@
|
||||
package gc;
|
||||
|
||||
class TestBigStack
|
||||
{
|
||||
var refs:Array<TestBigStack>;
|
||||
var self:TestBigStack;
|
||||
|
||||
public function new()
|
||||
{
|
||||
refs = [];
|
||||
self = this;
|
||||
}
|
||||
|
||||
function check()
|
||||
{
|
||||
if (self!=this)
|
||||
throw("Bad self reference");
|
||||
}
|
||||
|
||||
|
||||
function checkRec()
|
||||
{
|
||||
if (self!=this)
|
||||
throw("Bad self reference");
|
||||
for(r in refs)
|
||||
r.checkRec();
|
||||
}
|
||||
|
||||
function runRec(depth:Int)
|
||||
{
|
||||
var d = depth-1;
|
||||
if (d==0)
|
||||
return this;
|
||||
var b0 = new TestBigStack().runRec(d);
|
||||
var b1 = new TestBigStack().runRec(d);
|
||||
var b2 = new TestBigStack().runRec(d);
|
||||
var b3 = new TestBigStack().runRec(d);
|
||||
var b4 = new TestBigStack().runRec(d);
|
||||
var b5 = new TestBigStack().runRec(d);
|
||||
var b6 = new TestBigStack().runRec(d);
|
||||
var b7 = new TestBigStack().runRec(d);
|
||||
var b8 = new TestBigStack().runRec(d);
|
||||
var b9 = new TestBigStack().runRec(d);
|
||||
var b10 = new TestBigStack().runRec(d);
|
||||
var b11 = new TestBigStack().runRec(d);
|
||||
var b12 = new TestBigStack().runRec(d);
|
||||
var b13 = new TestBigStack().runRec(d);
|
||||
var b14 = new TestBigStack().runRec(d);
|
||||
var b15 = new TestBigStack().runRec(d);
|
||||
var b16 = new TestBigStack().runRec(d);
|
||||
var b17 = new TestBigStack().runRec(d);
|
||||
var b18 = new TestBigStack().runRec(d);
|
||||
var b19 = new TestBigStack().runRec(d);
|
||||
refs.push(b0);
|
||||
b0.check();
|
||||
b1.check();
|
||||
b2.check();
|
||||
b3.check();
|
||||
b4.check();
|
||||
b5.check();
|
||||
b6.check();
|
||||
b7.check();
|
||||
b8.check();
|
||||
b9.check();
|
||||
b10.check();
|
||||
b11.check();
|
||||
b12.check();
|
||||
b13.check();
|
||||
b14.check();
|
||||
b15.check();
|
||||
b16.check();
|
||||
b17.check();
|
||||
b18.check();
|
||||
b19.check();
|
||||
return this;
|
||||
}
|
||||
|
||||
function run(passes:Int, depth:Int)
|
||||
{
|
||||
for(p in 0...passes)
|
||||
{
|
||||
//if ( (p%1000)==0 )
|
||||
// Sys.println('Pass $p...');
|
||||
refs = [];
|
||||
runRec(depth);
|
||||
checkRec();
|
||||
}
|
||||
}
|
||||
|
||||
public static function test() : Bool
|
||||
{
|
||||
try {
|
||||
var b = new TestBigStack();
|
||||
b.run(5000,5);
|
||||
return true;
|
||||
}
|
||||
catch(e:Dynamic)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
129
Kha/Backends/Kinc-hxcpp/khacpp/test/haxe/gc/TestGC.hx
Normal file
129
Kha/Backends/Kinc-hxcpp/khacpp/test/haxe/gc/TestGC.hx
Normal file
@ -0,0 +1,129 @@
|
||||
package gc;
|
||||
import haxe.io.Bytes;
|
||||
import cpp.vm.Gc;
|
||||
|
||||
class CustomObject {
|
||||
public function new():Void {}
|
||||
}
|
||||
|
||||
class TestGC extends haxe.unit.TestCase {
|
||||
function createDummy(val:Dynamic):Dynamic {
|
||||
return { dummy: val };
|
||||
}
|
||||
|
||||
function gc():Dynamic {
|
||||
Gc.run(true);
|
||||
return Gc.getNextZombie();
|
||||
}
|
||||
|
||||
/**
|
||||
For avoiding the simple call being optimized in some way.
|
||||
*/
|
||||
function create(f:Void->Void):Void {
|
||||
f();
|
||||
clearStack(10);
|
||||
}
|
||||
|
||||
function clearStack(count:Int, ?nothing:Dynamic):Dynamic
|
||||
{
|
||||
if (count==0)
|
||||
return 0;
|
||||
return clearStack(count-1);
|
||||
}
|
||||
|
||||
|
||||
function createAbc():Void {
|
||||
var object = { test: "abc" };
|
||||
Gc.doNotKill(object);
|
||||
}
|
||||
public function testObject():Void {
|
||||
create(createAbc);
|
||||
var zombie = gc();
|
||||
assertTrue(zombie != null);
|
||||
assertEquals("abc", zombie.test);
|
||||
assertTrue(gc() == null);
|
||||
}
|
||||
|
||||
// Null<int> for numbers < 256 are special cases
|
||||
// Infact, there are no guarantees that Null<Int> will be actual objects in the future
|
||||
/*
|
||||
function create1234():Void {
|
||||
var object:Null<Int> = 1234;
|
||||
Gc.doNotKill(object);
|
||||
};
|
||||
public function testBoxedInt():Void {
|
||||
create(create1234);
|
||||
var zombie:Dynamic = gc();
|
||||
assertTrue(zombie != null);
|
||||
assertEquals(1234, zombie);
|
||||
assertTrue(gc() == null);
|
||||
}
|
||||
*/
|
||||
|
||||
function createFunction():Void {
|
||||
var object = function() return "abc";
|
||||
Gc.doNotKill(object);
|
||||
};
|
||||
public function testFunc():Void {
|
||||
create(createFunction);
|
||||
var zombie = gc();
|
||||
assertTrue(zombie != null);
|
||||
assertEquals("abc", zombie());
|
||||
assertTrue(gc() == null);
|
||||
}
|
||||
|
||||
function createCustom():Void {
|
||||
var object = new CustomObject();
|
||||
Gc.doNotKill(object);
|
||||
};
|
||||
public function testCustomObject():Void {
|
||||
create(createCustom);
|
||||
var zombie = gc();
|
||||
assertTrue(zombie != null);
|
||||
assertTrue(Std.isOfType(zombie, CustomObject));
|
||||
assertTrue(gc() == null);
|
||||
}
|
||||
|
||||
function createBytes():Void {
|
||||
var object = Bytes.alloc(1);
|
||||
Gc.doNotKill(object);
|
||||
};
|
||||
public function testBytes():Void {
|
||||
create(createBytes);
|
||||
var zombie = gc();
|
||||
assertTrue(zombie != null);
|
||||
assertTrue(Std.isOfType(zombie, Bytes));
|
||||
assertTrue(gc() == null);
|
||||
}
|
||||
|
||||
public function testBigStack():Void {
|
||||
assertTrue( TestBigStack.test() );
|
||||
}
|
||||
|
||||
#if !cppia
|
||||
public function testConstStrings():Void {
|
||||
// Const strings void Gc overhead
|
||||
var strings = new Array<String>();
|
||||
strings.push( haxe.Resource.getString("TestMain.hx") );
|
||||
strings.push( "some string" );
|
||||
var chars = "abc123";
|
||||
// Optimization for single chars...
|
||||
for(c in 0...chars.length)
|
||||
strings.push( chars.substr(c,1) );
|
||||
for(string in strings)
|
||||
assertTrue( untyped __global__.__hxcpp_is_const_string(string) );
|
||||
Gc.run(true);
|
||||
for(string in strings)
|
||||
assertTrue( untyped __global__.__hxcpp_is_const_string(string) );
|
||||
|
||||
var strings = new Array<String>();
|
||||
strings.push( haxe.Resource.getString("TestMain.hx").substr(10) );
|
||||
strings.push( "some string" + chars );
|
||||
for(c in 0...chars.length-1)
|
||||
strings.push( chars.substr(c,2) );
|
||||
|
||||
for(string in strings)
|
||||
assertFalse( untyped __global__.__hxcpp_is_const_string(string) );
|
||||
}
|
||||
#end
|
||||
}
|
134
Kha/Backends/Kinc-hxcpp/khacpp/test/haxe/gc/TestGCThreaded.hx
Normal file
134
Kha/Backends/Kinc-hxcpp/khacpp/test/haxe/gc/TestGCThreaded.hx
Normal file
@ -0,0 +1,134 @@
|
||||
package gc;
|
||||
import haxe.io.Bytes;
|
||||
import haxe.crypto.Md5;
|
||||
import cpp.vm.Gc;
|
||||
import sys.io.File;
|
||||
#if haxe4
|
||||
import sys.thread.Thread;
|
||||
#else
|
||||
import cpp.vm.Thread;
|
||||
#end
|
||||
|
||||
class Wrapper
|
||||
{
|
||||
public var a:Int;
|
||||
public function new(inA:Int) a = inA;
|
||||
}
|
||||
|
||||
|
||||
@:cppInclude("./ZoneTest.cpp")
|
||||
@:depend("./ZoneTest.cpp")
|
||||
class TestGCThreaded extends haxe.unit.TestCase
|
||||
{
|
||||
@:keep
|
||||
static var keepRunning = false;
|
||||
@:keep
|
||||
static var nativeRunning = false;
|
||||
var bigText:String;
|
||||
|
||||
|
||||
override public function setup()
|
||||
{
|
||||
var lines = [ for(i in 0...100000) "abc123\n" ];
|
||||
#if nme
|
||||
bigText = lines.join("");
|
||||
#else
|
||||
File.saveContent( "gc/big.txt", lines.join("") );
|
||||
#end
|
||||
}
|
||||
|
||||
public function testThreadOnce():Void
|
||||
{
|
||||
startNative();
|
||||
doThreadedWork(4,100);
|
||||
stopNative();
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
|
||||
public function testThreadMany():Void
|
||||
{
|
||||
startNative();
|
||||
for(i in 0...10)
|
||||
#if nme
|
||||
doThreadedWork(4,100);
|
||||
#else
|
||||
doThreadedWork(100,100);
|
||||
#end
|
||||
stopNative();
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@:native("nativeLoop")
|
||||
extern static function nativeLoop() : Void;
|
||||
|
||||
function startNative()
|
||||
{
|
||||
Thread.create( () -> {
|
||||
nativeRunning = true;
|
||||
keepRunning = true;
|
||||
nativeLoop();
|
||||
});
|
||||
}
|
||||
function stopNative()
|
||||
{
|
||||
keepRunning = false;
|
||||
while(nativeRunning)
|
||||
Sys.sleep(0.1);
|
||||
}
|
||||
|
||||
function doThreadedWork(numThreads, numWork):Void
|
||||
{
|
||||
var threads:Array<Thread> = makeThreads(numThreads);
|
||||
|
||||
for (i in 0...numWork)
|
||||
threads[i % threads.length].sendMessage('doWork');
|
||||
|
||||
for (i in 0...numThreads)
|
||||
{
|
||||
threads[i].sendMessage('exit');
|
||||
Thread.readMessage(true);
|
||||
}
|
||||
}
|
||||
|
||||
function makeThreads(numThreads:Int):Array<Thread>
|
||||
{
|
||||
#if nme
|
||||
var text:String = bigText;
|
||||
#else
|
||||
var text:String = File.getContent("gc/big.txt");
|
||||
#end
|
||||
var main:Thread = Thread.current();
|
||||
var threads:Array<Thread> = [];
|
||||
for (i in 0...numThreads)
|
||||
{
|
||||
threads.push( Thread.create(function() {
|
||||
while(true) {
|
||||
var message:Dynamic = Thread.readMessage(true);
|
||||
if(message == 'exit')
|
||||
break;
|
||||
else
|
||||
Md5.encode(text);
|
||||
var arrays = new Array<Array<Wrapper>>();
|
||||
for(i in 0...100)
|
||||
{
|
||||
var wrappers = new Array<Wrapper>();
|
||||
arrays.push(wrappers);
|
||||
for(j in 0...1000)
|
||||
wrappers.push( new Wrapper(1) );
|
||||
}
|
||||
var sum = 0;
|
||||
for(a in arrays)
|
||||
for(w in a)
|
||||
sum += w.a;
|
||||
|
||||
assertTrue(sum==100000);
|
||||
}
|
||||
main.sendMessage('done');
|
||||
}) );
|
||||
}
|
||||
return threads;
|
||||
}
|
||||
|
||||
}
|
||||
|
15
Kha/Backends/Kinc-hxcpp/khacpp/test/haxe/gc/ZoneTest.cpp
Normal file
15
Kha/Backends/Kinc-hxcpp/khacpp/test/haxe/gc/ZoneTest.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
void nativeLoop()
|
||||
{
|
||||
while( gc::TestGCThreaded_obj::keepRunning)
|
||||
{
|
||||
|
||||
for(int i=0; i<100; i++)
|
||||
::gc::Wrapper_obj::__alloc( HX_CTX_GET ,1);
|
||||
|
||||
::Sys_obj::sleep(0.01);
|
||||
}
|
||||
gc::TestGCThreaded_obj::nativeRunning = false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user