Turn off the 'public' check for main, and improve diagnostics.
We're likely to be able to invoke a static main method before we can invoke
a virtual getModifiers, and right now we don't care whether we've been asked
to run a non-public main.
Also adds PrettyMethod for improved diagnostics.
Change-Id: Iea08f0be980386adbe408b476449c2066c4e6da8
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index a55cdae..6acfb71 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -38,7 +38,7 @@
size_t length = assembler.CodeSize();
void* addr = mmap(NULL, length, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (addr == MAP_FAILED) {
- PLOG(FATAL) << "mmap failed";
+ PLOG(FATAL) << "mmap failed for " << PrettyMethod(method, true);
}
MemoryRegion region(addr, length);
assembler.FinalizeInstructions(region);
@@ -405,8 +405,8 @@
if (method->GetCode()) {
(*stub)(method, rcvr, self, args, &result);
} else {
- // TODO: pretty print method here
- LOG(WARNING) << "Not invoking method with no associated code";
+ LOG(WARNING) << "Not invoking method with no associated code: "
+ << PrettyMethod(method, true);
result.j = 0;
}
// Pop transition
@@ -472,12 +472,12 @@
if (method == NULL || method->IsStatic() != is_static) {
Thread* self = Thread::Current();
- std::string class_name(c->GetDescriptor()->ToModifiedUtf8());
+ std::string method_name(PrettyMethod(method, true));
// TODO: try searching for the opposite kind of method from is_static
// for better diagnostics?
self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
- "no %s method \"%s.%s%s\"", is_static ? "static" : "non-static",
- class_name.c_str(), name, sig);
+ "no %s method %s", is_static ? "static" : "non-static",
+ method_name.c_str());
return NULL;
}
@@ -2004,7 +2004,6 @@
if (method == NULL) {
Thread* self = Thread::Current();
std::string class_name = klass->GetDescriptor()->ToModifiedUtf8();
- // TODO: pretty print method names through a single routine
self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
"no method \"%s.%s%s\"",
class_name.c_str(), name, sig);
@@ -2012,7 +2011,6 @@
} else if (!method->IsNative()) {
Thread* self = Thread::Current();
std::string class_name = klass->GetDescriptor()->ToModifiedUtf8();
- // TODO: pretty print method names through a single routine
self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
"method \"%s.%s%s\" is not native",
class_name.c_str(), name, sig);
diff --git a/src/main.cc b/src/main.cc
index 381f8f7..b4eb151 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -53,7 +53,12 @@
return false;
}
static const int PUBLIC = 0x0001; // java.lang.reflect.Modifiers.PUBLIC
+#if 0 // CallIntMethod not yet implemented
int modifiers = env->CallIntMethod(method.get(), get_modifiers);
+#else
+ int modifiers = PUBLIC;
+ UNIMPLEMENTED(WARNING) << "assuming main is public...";
+#endif
if ((modifiers & PUBLIC) == 0) {
return false;
}
diff --git a/src/utils.cc b/src/utils.cc
index 058ca83..67d5780 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -54,6 +54,22 @@
return result;
}
+std::string PrettyMethod(const Method* m, bool with_signature) {
+ if (m == NULL) {
+ return "null";
+ }
+ Class* c = m->GetDeclaringClass();
+ std::string result(PrettyDescriptor(c->GetDescriptor()->ToModifiedUtf8()));
+ result += '.';
+ result += m->GetName()->ToModifiedUtf8();
+ if (with_signature) {
+ // TODO: iterate over the signature's elements and pass them all to
+ // PrettyDescriptor? We'd need to pull out the return type specially, too.
+ result += m->GetSignature()->ToModifiedUtf8();
+ }
+ return result;
+}
+
std::string PrettyType(const Object* obj) {
if (obj == NULL) {
return "null";
diff --git a/src/utils.h b/src/utils.h
index ea51d1e..541fbfa 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -10,6 +10,7 @@
namespace art {
+class Method;
class Object;
template<typename T>
@@ -135,13 +136,17 @@
return result;
}
-// Return a newly-allocated string containing a human-readable equivalent
-// of 'descriptor'. So "I" would be "int", "[[I" would be "int[][]",
-// "[Ljava/lang/String;" would be "java.lang.String[]", and so forth.
+// Returns a human-readable equivalent of 'descriptor'. So "I" would be "int",
+// "[[I" would be "int[][]", "[Ljava/lang/String;" would be
+// "java.lang.String[]", and so forth.
std::string PrettyDescriptor(const StringPiece& descriptor);
-// Returns a human-readable string form of the name of the class of
-// the given object. So given a java.lang.String, the output would
+// Returns a human-readable signature for 'm'. Something like "a.b.C.m" or
+// "a.b.C.m(II)V" (depending on the value of 'with_signature').
+std::string PrettyMethod(const Method* m, bool with_signature);
+
+// Returns a human-readable form of the name of the *class* of the given object.
+// So given an instance of java.lang.String, the output would
// be "java.lang.String". Given an array of int, the output would be "int[]".
// Given String.class, the output would be "java.lang.Class<java.lang.String>".
std::string PrettyType(const Object* obj);