OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [java/] [lang/] [natVMClassLoader.cc] - Blame information for rev 758

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 758 jeremybenn
// natVMClassLoader.cc - VMClassLoader native methods
2
 
3
/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006  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
/* Author: Kresten Krab Thorup <krab@gnu.org>  */
12
 
13
#include <config.h>
14
 
15
#include <stdlib.h>
16
#include <string.h>
17
 
18
#include <gcj/cni.h>
19
#include <jvm.h>
20
 
21
#include <java-threads.h>
22
#include <java-interp.h>
23
 
24
#include <java/lang/VMClassLoader.h>
25
#include <java/lang/VMCompiler.h>
26
#include <gnu/gcj/runtime/ExtensionClassLoader.h>
27
#include <gnu/gcj/runtime/SystemClassLoader.h>
28
#include <gnu/gcj/runtime/BootClassLoader.h>
29
#include <java/lang/ClassLoader.h>
30
#include <java/lang/Class.h>
31
#include <java/lang/Throwable.h>
32
#include <java/security/ProtectionDomain.h>
33
#include <java/lang/ClassFormatError.h>
34
#include <java/lang/StringBuffer.h>
35
#include <java/lang/SecurityManager.h>
36
#include <java/lang/Runtime.h>
37
#include <java/util/HashSet.h>
38
#include <java/lang/SecurityException.h>
39
#include <java/lang/VirtualMachineError.h>
40
 
41
java::lang::Class *
42
java::lang::VMClassLoader::defineClass (java::lang::ClassLoader *loader,
43
                                        jstring name,
44
                                        jbyteArray data,
45
                                        jint offset,
46
                                        jint length,
47
                                        java::security::ProtectionDomain *pd)
48
{
49
  jclass klass = VMCompiler::compileClass(loader, name, data,
50
                                          offset, length, pd);
51
 
52
  if (klass)
53
    _Jv_RegisterInitiatingLoader (klass, klass->loader);
54
 
55
#ifdef INTERPRETER
56
  if (klass == NULL)
57
    {
58
      klass = new java::lang::Class ();
59
 
60
      // Synchronize on the class, so that it is not attempted initialized
61
      // until we're done loading.
62
      JvSynchronize sync (klass);
63
 
64
      // Record the defining loader.  For the bootstrap class loader,
65
      // we record NULL.
66
      if (loader != bootLoader)
67
        klass->loader = loader;
68
 
69
      if (name != 0)
70
        {
71
          _Jv_Utf8Const *name2 = _Jv_makeUtf8Const (name);
72
 
73
          if (! _Jv_VerifyClassName (name2))
74
            throw new java::lang::ClassFormatError
75
              (JvNewStringLatin1 ("erroneous class name"));
76
 
77
          klass->name = name2;
78
        }
79
 
80
      _Jv_Utf8Const *found_name = NULL;
81
      try
82
        {
83
          _Jv_DefineClass (klass, data, offset, length, pd, &found_name);
84
        }
85
      catch (java::lang::Throwable *ex)
86
        {
87
          klass->state = JV_STATE_ERROR;
88
          klass->notifyAll ();
89
 
90
          if (found_name != NULL)
91
            _Jv_UnregisterInitiatingLoader (klass, klass->loader);
92
 
93
          // If EX is not a ClassNotFoundException, that's ok, because we
94
          // account for the possibility in defineClass().
95
          throw ex;
96
        }
97
 
98
      // if everything proceeded sucessfully, we're loaded.
99
      JvAssert (klass->state == JV_STATE_READ);
100
    }
101
#endif // INTERPRETER
102
 
103
  if (! klass)
104
    {
105
      StringBuffer *sb = new StringBuffer();
106
      if (name)
107
        {
108
          sb->append(JvNewStringLatin1("found class file for class "));
109
          sb->append(name);
110
        }
111
      else
112
        sb->append(JvNewStringLatin1("found unnamed class file"));
113
      sb->append(JvNewStringLatin1(", but no interpreter configured in this libgcj"));
114
      throw new VirtualMachineError(sb->toString());
115
    }
116
 
117
  return klass;
118
}
119
 
120
java::lang::ClassLoader *
121
java::lang::VMClassLoader::getSystemClassLoaderInternal()
122
{
123
  _Jv_InitClass (&gnu::gcj::runtime::ExtensionClassLoader::class$);
124
  _Jv_CopyClassesToSystemLoader (gnu::gcj::runtime::ExtensionClassLoader::system_instance);
125
  return gnu::gcj::runtime::ExtensionClassLoader::system_instance;
126
}
127
 
128
jclass
129
java::lang::VMClassLoader::getPrimitiveClass (jchar type)
130
{
131
  char sig[2];
132
  sig[0] = (char) type;
133
  sig[1] = '\0';
134
  // Note: this cannot return NULL, since the input is always correct.
135
  return _Jv_FindClassFromSignature (sig, NULL);
136
}
137
 
138
void
139
java::lang::VMClassLoader::initBootLoader(jstring libdir)
140
{
141
  bootLoader = new gnu::gcj::runtime::BootClassLoader(libdir);
142
}
143
 
144
jclass
145
java::lang::VMClassLoader::nativeFindClass (jstring name)
146
{
147
  jclass klass = NULL;
148
 
149
  if (lib_control != LIB_NEVER)
150
    {
151
      // Turn `gnu.pkg.quux' into `lib-gnu-pkg-quux'.  Then search for
152
      // a module named (eg, on Linux) `lib-gnu-pkg-quux.so', followed
153
      // by `lib-gnu-pkg.so' and `lib-gnu.so'.  If loading one of
154
      // these causes the class to appear in the cache, then use it.
155
      java::lang::StringBuffer *sb
156
        = new java::lang::StringBuffer (JvNewStringLatin1("lib-"));
157
      // Skip inner classes
158
      jstring cn;
159
      jint ci = name->indexOf('$');
160
      if (ci == -1)
161
        cn = name;
162
      else
163
        cn = name->substring (0, ci);
164
      jstring so_base_name
165
        = (sb->append (cn)->toString ())->replace ('.', '-');
166
 
167
      using namespace ::java::lang;
168
      Runtime *rt = Runtime::getRuntime();
169
 
170
      _Jv_Utf8Const *name_u = NULL;
171
 
172
      // Compare against `3' because that is the length of "lib".
173
      while (! klass && so_base_name && so_base_name->length() > 3)
174
        {
175
          if (lib_control == LIB_CACHE)
176
            {
177
              // If we've already tried this name, we're done.
178
              if (tried_libraries->contains(so_base_name))
179
                break;
180
              tried_libraries->add(so_base_name);
181
            }
182
 
183
          jboolean loaded = rt->loadLibraryInternal (so_base_name);
184
 
185
          jint nd = so_base_name->lastIndexOf ('-');
186
          if (nd == -1)
187
            so_base_name = NULL;
188
          else
189
            so_base_name = so_base_name->substring (0, nd);
190
 
191
          if (loaded)
192
            {
193
              if (name_u == NULL)
194
                name_u = _Jv_makeUtf8Const (name);
195
              klass = _Jv_FindClassInCache (name_u);
196
            }
197
        }
198
    }
199
 
200
  if (klass)
201
    definePackageForNative(name);
202
 
203
  return klass;
204
}
205
 
206
jclass
207
java::lang::VMClassLoader::loadClass(jstring name, jboolean resolve)
208
{
209
  using namespace ::java::lang;
210
 
211
  SecurityManager *sm = (SecurityManager *)SecurityManager::current;
212
  if (sm)
213
    {
214
      jint lastDot = name->lastIndexOf('.');
215
      if (lastDot != -1)
216
        sm->checkPackageAccess(name->substring(0, lastDot));
217
    }
218
 
219
  // We try the boot loader first, so that the endorsed directory
220
  // overrides compiled-in classes.
221
  jclass klass = NULL;
222
  if (bootLoader)
223
    klass = bootLoader->bootLoadClass(name);
224
  if (! klass)
225
    {
226
      _Jv_Utf8Const *utf = _Jv_makeUtf8Const (name);
227
      klass = _Jv_FindClassInCache (utf);
228
    }
229
  if (! klass)
230
    klass = nativeFindClass(name);
231
  if (klass)
232
    {
233
      // We never want to return a class without its supers linked.
234
      // It isn't clear from the spec, but this is what other
235
      // implementations do in practice.
236
      if (resolve)
237
        resolveClass (klass);
238
      else
239
        _Jv_Linker::wait_for_state (klass, JV_STATE_LOADING);
240
 
241
      definePackageForNative(name);
242
    }
243
 
244
  return klass;
245
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.