Merge remote-tracking branch 'refs/remotes/ReadyTalk/master' into avian-droid

This commit is contained in:
Ilya Mizus 2014-02-21 03:53:12 +03:00
commit a1d98280ab
9 changed files with 134 additions and 131 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ bin
/distrib /distrib
*.pdb *.pdb
*.swp *.swp
/*.sublime-*

View File

@ -56,7 +56,7 @@ public class ConcurrentLinkedQueue<T> {
return poll(true); return poll(true);
} }
public T poll(boolean remove) { private T poll(boolean remove) {
while (true) { while (true) {
Node<T> h = head; Node<T> h = head;
Node<T> t = tail; Node<T> t = tail;

View File

@ -698,15 +698,6 @@ class MyClasspath : public Classpath {
#else // not AVIAN_OPENJDK_SRC #else // not AVIAN_OPENJDK_SRC
expect(t, loadLibrary(t, libraryPath, "verify", true, true)); expect(t, loadLibrary(t, libraryPath, "verify", true, true));
expect(t, loadLibrary(t, libraryPath, "java", true, true)); expect(t, loadLibrary(t, libraryPath, "java", true, true));
# ifndef PLATFORM_WINDOWS
// at one point, loading libmawt ahead of time was necessary to
// make AWT work, but recent versions of OpenJDK seem to take care
// of this from Java code, in which case loading it ahead of time
// actually causes trouble, so we comment it out for now until we
// know exactly when it's needed:
//loadLibrary(t, libraryPath, "mawt", true, true, false);
# endif
#endif // not AVIAN_OPENJDK_SRC #endif // not AVIAN_OPENJDK_SRC
{ object assertionLock = resolveField { object assertionLock = resolveField

View File

@ -3234,7 +3234,11 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall)
Compiler::Operand* result = 0; Compiler::Operand* result = 0;
if (emptyMethod(t, target)) { // don't bother calling an empty method unless calling it might
// cause the class to be initialized, which may have side effects
if (emptyMethod(t, target)
and (not classNeedsInit(t, methodClass(t, target))))
{
tailCall = false; tailCall = false;
} else { } else {
BootContext* bc = frame->context->bootContext; BootContext* bc = frame->context->bootContext;

View File

@ -23,6 +23,16 @@ public class Misc {
} }
} }
private static class Static {
static {
staticRan = true;
}
public static void run() { }
}
private static boolean staticRan;
private static int alpha; private static int alpha;
private static int beta; private static int beta;
private static byte byte1, byte2, byte3; private static byte byte1, byte2, byte3;
@ -299,6 +309,10 @@ public class Misc {
} catch (java.net.UnknownHostException e) { } catch (java.net.UnknownHostException e) {
// cool // cool
} }
expect(! staticRan);
Static.run();
expect(staticRan);
} }
protected class Protected { } protected class Protected { }

View File

@ -62,35 +62,21 @@ public:
}; };
class BasicAssemblerTest : public Test { TEST(BasicAssembler) {
public: BasicEnv env;
BasicAssemblerTest(): Asm a(env);
Test("BasicAssembler") }
{}
virtual void run() { TEST(ArchitecturePlan) {
BasicEnv env; BasicEnv env;
Asm a(env);
for(int op = (int)lir::Call; op < (int)lir::AlignedJump; op++) {
bool thunk;
OperandMask mask;
env.arch->plan((lir::UnaryOperation)op, vm::TargetBytesPerWord, mask, &thunk);
assertFalse(thunk);
assertNotEqual(static_cast<uint8_t>(0), mask.typeMask);
assertNotEqual(static_cast<uint64_t>(0), mask.registerMask);
} }
} basicAssemblerTest;
class ArchitecturePlanTest : public Test { }
public:
ArchitecturePlanTest():
Test("ArchitecturePlan")
{}
virtual void run() {
BasicEnv env;
for(int op = (int)lir::Call; op < (int)lir::AlignedJump; op++) {
bool thunk;
OperandMask mask;
env.arch->plan((lir::UnaryOperation)op, vm::TargetBytesPerWord, mask, &thunk);
assertFalse(thunk);
assertNotEqual(static_cast<uint8_t>(0), mask.typeMask);
assertNotEqual(static_cast<uint64_t>(0), mask.registerMask);
}
}
} architecturePlanTest;

View File

@ -19,26 +19,19 @@ using namespace avian::codegen;
using namespace vm; using namespace vm;
class RegisterIteratorTest : public Test { TEST(RegisterIterator) {
public: RegisterMask regs(0x55);
RegisterIteratorTest(): assertEqual<unsigned>(0, regs.start);
Test("RegisterIterator") assertEqual<unsigned>(7, regs.limit);
{}
virtual void run() { RegisterIterator it(regs);
RegisterMask regs(0x55); assertTrue(it.hasNext());
assertEqual<unsigned>(0, regs.start); assertEqual<unsigned>(0, it.next());
assertEqual<unsigned>(7, regs.limit); assertTrue(it.hasNext());
assertEqual<unsigned>(2, it.next());
RegisterIterator it(regs); assertTrue(it.hasNext());
assertTrue(it.hasNext()); assertEqual<unsigned>(4, it.next());
assertEqual<unsigned>(0, it.next()); assertTrue(it.hasNext());
assertTrue(it.hasNext()); assertEqual<unsigned>(6, it.next());
assertEqual<unsigned>(2, it.next()); assertFalse(it.hasNext());
assertTrue(it.hasNext()); }
assertEqual<unsigned>(4, it.next());
assertTrue(it.hasNext());
assertEqual<unsigned>(6, it.next());
assertFalse(it.hasNext());
}
} registerIteratorTest;

View File

@ -15,38 +15,41 @@
#include <stdio.h> #include <stdio.h>
class Test { class Test {
private: private:
Test* next; Test* next;
static Test* first; static Test* first;
static Test** last; static Test** last;
friend int main(int argc, char** argv); friend int main(int argc, char** argv);
void print(uint64_t value)
void print(uint64_t value) { {
fprintf(stderr, "%p", reinterpret_cast<void*>(value)); fprintf(stderr, "%p", reinterpret_cast<void*>(value));
} }
void print(uint32_t value) { void print(uint32_t value)
{
fprintf(stderr, "%p", reinterpret_cast<void*>(value)); fprintf(stderr, "%p", reinterpret_cast<void*>(value));
} }
void print(uint8_t value) { void print(uint8_t value)
{
print(static_cast<uint32_t>(value)); print(static_cast<uint32_t>(value));
} }
void print(bool value) { void print(bool value)
{
fprintf(stderr, "%s", value ? "true" : "false"); fprintf(stderr, "%s", value ? "true" : "false");
} }
int failures; int failures;
int runs; int runs;
protected: protected:
template<class T> template <class T>
void assertEqual(T expected, T actual) { void assertEqual(T expected, T actual)
if(expected != actual) { {
if (expected != actual) {
fprintf(stderr, "assertion failure, expected: "); fprintf(stderr, "assertion failure, expected: ");
print(expected); print(expected);
fprintf(stderr, ", actual: "); fprintf(stderr, ", actual: ");
@ -57,17 +60,23 @@ protected:
runs++; runs++;
} }
void assertEqual(const char* expected, const char* actual) { void assertEqual(const char* expected, const char* actual)
if((expected == 0 && actual != 0) || (expected != 0 && actual == 0) || strcmp(expected, actual) != 0) { {
fprintf(stderr, "assertion failure, expected: \"%s\", actual: \"%s\"\n", expected, actual); if ((expected == 0 && actual != 0) || (expected != 0 && actual == 0)
|| strcmp(expected, actual) != 0) {
fprintf(stderr,
"assertion failure, expected: \"%s\", actual: \"%s\"\n",
expected,
actual);
failures++; failures++;
} }
runs++; runs++;
} }
template<class T> template <class T>
void assertNotEqual(T expected, T actual) { void assertNotEqual(T expected, T actual)
if(expected == actual) { {
if (expected == actual) {
fprintf(stderr, "assertion failure, expected: not "); fprintf(stderr, "assertion failure, expected: not ");
print(expected); print(expected);
fprintf(stderr, ", actual: "); fprintf(stderr, ", actual: ");
@ -78,15 +87,17 @@ protected:
runs++; runs++;
} }
void assertTrue(bool value) { void assertTrue(bool value)
{
assertEqual(true, value); assertEqual(true, value);
} }
void assertFalse(bool value) { void assertFalse(bool value)
{
assertEqual(false, value); assertEqual(false, value);
} }
public: public:
const char* const name; const char* const name;
Test(const char* name); Test(const char* name);
@ -95,4 +106,14 @@ public:
static bool runAll(); static bool runAll();
}; };
#endif // TEST_HARNESS_H #define TEST(name) \
class name##TestClass : public Test { \
public: \
name##TestClass() : Test(#name) \
{ \
} \
virtual void run(); \
} name##TestInstance; \
void name##TestClass::run()
#endif // TEST_HARNESS_H

View File

@ -19,51 +19,44 @@
using namespace avian::util; using namespace avian::util;
class ArgParserTest : public Test { TEST(ArgParser) {
public: {
ArgParserTest(): ArgParser parser;
Test("ArgParser") Arg arg1(parser, false, "arg1", "<value>");
{} Arg required2(parser, true, "required2", "<value>");
const char* args[] = {
virtual void run() { "myExecutable",
{ "-arg1", "myValue1",
ArgParser parser; "-required2", "myRequired2",
Arg arg1(parser, false, "arg1", "<value>"); 0
Arg required2(parser, true, "required2", "<value>"); };
const char* args[] = { assertTrue(parser.parse(sizeof(args) / sizeof(char*) - 1, args));
"myExecutable", assertEqual("myValue1", arg1.value);
"-arg1", "myValue1", assertEqual("myRequired2", required2.value);
"-required2", "myRequired2",
0
};
assertTrue(parser.parse(sizeof(args) / sizeof(char*) - 1, args));
assertEqual("myValue1", arg1.value);
assertEqual("myRequired2", required2.value);
}
{
ArgParser parser;
Arg arg1(parser, false, "arg1", "<value>");
Arg required2(parser, true, "required2", "<value>");
const char* args[] = {
"myExecutable",
"-arg1", "myValue1",
"-required2",
0
};
assertFalse(parser.parse(sizeof(args) / sizeof(char*) - 1, args));
}
{
ArgParser parser;
Arg arg1(parser, false, "arg1", "<value>");
Arg required2(parser, true, "required2", "<value>");
const char* args[] = {
"myExecutable",
"-arg1", "myValue1",
0
};
assertFalse(parser.parse(sizeof(args) / sizeof(char*) - 1, args));
}
} }
} argParserTest;
{
ArgParser parser;
Arg arg1(parser, false, "arg1", "<value>");
Arg required2(parser, true, "required2", "<value>");
const char* args[] = {
"myExecutable",
"-arg1", "myValue1",
"-required2",
0
};
assertFalse(parser.parse(sizeof(args) / sizeof(char*) - 1, args));
}
{
ArgParser parser;
Arg arg1(parser, false, "arg1", "<value>");
Arg required2(parser, true, "required2", "<value>");
const char* args[] = {
"myExecutable",
"-arg1", "myValue1",
0
};
assertFalse(parser.parse(sizeof(args) / sizeof(char*) - 1, args));
}
}