OSDN Git Service

2b8f8d4a5109bf65b6a8561c431e19f269057e12
[pf3gnuchains/gcc-fork.git] / libjava / gnu / gcj / runtime / natFirstThread.cc
1 // natFirstThread.cc - Implementation of FirstThread native methods.
2
3 /* Copyright (C) 1998, 1999  Red Hat, Inc.
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 <stdlib.h>
14
15 #include <gcj/cni.h>
16 #include <jvm.h>
17
18 #include <gnu/gcj/runtime/FirstThread.h>
19 #include <java/lang/Class.h>
20 #include <java/lang/String.h>
21 #include <java/lang/System.h>
22 #include <java/lang/reflect/Modifier.h>
23 #include <java/io/PrintStream.h>
24
25 #define DIE(Message)  die (JvNewStringLatin1 (Message))
26
27 typedef void main_func (jobject);
28
29 void
30 gnu::gcj::runtime::FirstThread::run (void)
31 {
32   Utf8Const* main_signature = _Jv_makeUtf8Const ("([Ljava.lang.String;)V", 22);
33   Utf8Const* main_name = _Jv_makeUtf8Const ("main", 4);
34
35   if (klass == NULL)
36     {
37       klass = java::lang::Class::forName (klass_name);
38       if (klass != NULL) _Jv_InitClass (klass);
39     }
40
41   _Jv_Method *meth = _Jv_GetMethodLocal (klass, main_name, main_signature);
42
43   // Some checks from Java Spec section 12.1.4.
44   if (meth == NULL)
45     DIE ("no suitable method `main' in class");
46   if (! java::lang::reflect::Modifier::isStatic(meth->accflags))
47     DIE ("`main' must be static");
48   if (! java::lang::reflect::Modifier::isPublic(meth->accflags))
49     DIE ("`main' must be public");
50
51   main_func *real_main = (main_func *) meth->ncode;
52   (*real_main) (args);
53 }