1 // natMainThread.cc - Implementation of MainThread native methods.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
18 #include <java-threads.h>
20 #include <gnu/java/lang/MainThread.h>
21 #include <java/lang/Runtime.h>
22 #include <java/lang/ThreadGroup.h>
24 typedef void main_func (jobject
);
27 gnu::java::lang::MainThread::call_main (void)
29 Utf8Const
* main_signature
= _Jv_makeUtf8Const ("([Ljava.lang.String;)V", 22);
30 Utf8Const
* main_name
= _Jv_makeUtf8Const ("main", 4);
32 _Jv_Method
*meth
= _Jv_LookupDeclaredMethod (klass
, main_name
,
35 // Some checks from Java Spec section 12.1.4.
36 const char *msg
= NULL
;
38 msg
= "no suitable method `main' in class";
39 else if (! ::java::lang::reflect::Modifier::isStatic(meth
->accflags
))
40 msg
= "`main' must be static";
41 else if (! ::java::lang::reflect::Modifier::isPublic(meth
->accflags
))
42 msg
= "`main' must be public";
45 fprintf (stderr
, "%s\n", msg
);
49 main_func
*real_main
= (main_func
*) meth
->ncode
;
52 // Note that we do thread cleanup here. We have to do this here and
53 // not in _Jv_RunMain; if we do if after the main thread has exited,
54 // our ThreadGroup will be null, and if Runtime.exit tries to create
55 // a new Thread (which it does when running shutdown hooks), it will
56 // eventually NPE due to this.
59 int status
= (int) ::java::lang::ThreadGroup::had_uncaught_exception
;
60 ::java::lang::Runtime
*runtime
= ::java::lang::Runtime::getRuntime ();
61 runtime
->exit (status
);