Skip to content

Commit

Permalink
ext: method converter
Browse files Browse the repository at this point in the history
Signed-off-by: imkiva <[email protected]>
  • Loading branch information
imkiva committed Jun 20, 2018
1 parent d016783 commit 791ec70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ext/objectConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Created by kiva on 2018/6/20.
//


#include <kivm/bytecode/invocationContext.h>
#include <kivm/runtime/javaThread.h>
#include <kivm/oop/instanceOop.h>
#include <kivm/oop/primitiveOop.h>
#include <kivm/oop/mirrorOop.h>
Expand All @@ -11,6 +12,28 @@
namespace helper {
using namespace kivm;

void callMethod(MethodID *method, const std::list<oop> &args) {
auto thread = Threads::currentThread();
if (thread == nullptr) {
// java.lang.IllegalStateException: not a Java thread
return;
}

InvocationContext::invokeWithArgs(thread, method->_method, args);
if (thread->isExceptionOccurred()) {
KiVM::uncaughtException(thread);
}
}

void convertMethods(InstanceKlass *instanceKlass) {
for (auto e : instanceKlass->getDeclaredMethods()) {
auto methodId = e.second;
if (methodId->_method->isStatic()) {
callMethod(methodId, {/* args */});
}
}
}

void convertStaticFields(InstanceKlass *instanceKlass) {
for (auto e : instanceKlass->getStaticFields()) {
auto fieldId = e.second;
Expand Down
4 changes: 4 additions & 0 deletions include/kivm/runtime/javaThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ namespace kivm {
inline bool isExceptionOccurred() const {
return _exceptionOop != nullptr;
}

inline instanceOop getException() const {
return _exceptionOop;
}
};

// The Java main thread
Expand Down

0 comments on commit 791ec70

Please sign in to comment.