1 // natFirstThread.cc - Implementation of FirstThread native methods.
2
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 #include <config.h>
12
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #include <gcj/cni.h>
17 #include <jvm.h>
18
19 #include <gnu/gcj/runtime/FirstThread.h>
20
21 typedef void main_func (jobject);
22
23 void
call_main(void)24 gnu::gcj::runtime::FirstThread::call_main (void)
25 {
26 Utf8Const* main_signature = _Jv_makeUtf8Const ("([Ljava.lang.String;)V", 22);
27 Utf8Const* main_name = _Jv_makeUtf8Const ("main", 4);
28
29 _Jv_Method *meth = _Jv_LookupDeclaredMethod (klass, main_name,
30 main_signature);
31
32 // Some checks from Java Spec section 12.1.4.
33 const char *msg = NULL;
34 if (meth == NULL)
35 msg = "no suitable method `main' in class";
36 else if (! java::lang::reflect::Modifier::isStatic(meth->accflags))
37 msg = "`main' must be static";
38 else if (! java::lang::reflect::Modifier::isPublic(meth->accflags))
39 msg = "`main' must be public";
40 if (msg != NULL)
41 {
42 fprintf (stderr, "%s\n", msg);
43 ::exit(1);
44 }
45
46 main_func *real_main = (main_func *) meth->ncode;
47 (*real_main) (args);
48 }
49