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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [gcj/] [runtime/] [natSharedLibLoader.cc] - Blame information for rev 861

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
// natSharedLibLoader.cc - Implementation of SharedLibHelper native methods.
2
 
3
/* Copyright (C) 2001, 2003, 2004, 2005, 2006, 2010  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
#include <platform.h>
13
 
14
#include <gcj/cni.h>
15
#include <jvm.h>
16
#include <execution.h>
17
 
18
#include <gnu/gcj/runtime/SharedLibHelper.h>
19
#include <java/io/IOException.h>
20
#include <java/lang/UnsupportedOperationException.h>
21
#include <java/lang/UnknownError.h>
22
 
23
#include <java/lang/VMClassLoader.h>
24
 
25
// If we're using the Boehm GC, then we need this include to override dlopen.
26
#ifdef HAVE_BOEHM_GC
27
// Set GC_DEBUG before including gc.h!
28
#ifdef LIBGCJ_GC_DEBUG
29
# define GC_DEBUG
30
#endif
31
#include <gc.h>
32
#endif /* HAVE_BOEHM_GC */
33
 
34
#ifdef HAVE_DLOPEN
35
#include <dlfcn.h>
36
 
37
/* Only used during dlopen, while having a lock on Class.class. */
38
static java::lang::ClassLoader *curLoader;
39
static gnu::gcj::runtime::SharedLibHelper *curHelper;
40
 
41
typedef void (*ClassHookFunc) (jclass);
42
typedef void (*CoreHookFunc) (_Jv_core_chain *);
43
 
44
void
45
_Jv_sharedlib_register_hook (jclass cls)
46
{
47
  cls->protectionDomain = curHelper->domain;
48
  cls->loader = curLoader;
49
  if (! cls->engine)
50
    cls->engine = &_Jv_soleCompiledEngine;
51
  curHelper->registerClass(cls->getName(), cls);
52
}
53
 
54
static void
55
core_hook (_Jv_core_chain *chain)
56
{
57
  chain->next = (_Jv_core_chain *) curHelper->core_chain;
58
  curHelper->core_chain = (gnu::gcj::RawData *) chain;
59
}
60
 
61
struct SharedLibDummy
62
{
63
  ClassHookFunc saved;
64
  CoreHookFunc saved_core;
65
  SharedLibDummy()
66
  {
67
    saved = _Jv_RegisterClassHook;
68
    saved_core = _Jv_RegisterCoreHook;
69
  }
70
  ~SharedLibDummy()
71
  {
72
    _Jv_RegisterClassHook = saved;
73
    _Jv_RegisterCoreHook = saved_core;
74
    curLoader = NULL;
75
  }
76
};
77
#endif
78
 
79
void
80
gnu::gcj::runtime::SharedLibHelper::init(void)
81
{
82
#ifdef HAVE_DLOPEN
83
  char *lname = (char *) __builtin_alloca (JvGetStringUTFLength (baseName)
84
                                           + 1);
85
  jsize total = JvGetStringUTFRegion (baseName, 0, baseName->length(), lname);
86
  lname[total] = '\0';
87
 
88
  if (flags==0)
89
    flags = RTLD_GLOBAL | RTLD_LAZY;
90
  JvSynchronize dummy1(&::java::lang::Class::class$);
91
  SharedLibDummy dummy2;
92
  curLoader = ((void*)loader == ::java::lang::VMClassLoader::bootLoader
93
               ? NULL : loader);
94
  curHelper = this;
95
  _Jv_RegisterClassHook = _Jv_sharedlib_register_hook;
96
  _Jv_RegisterCoreHook = core_hook;
97
  void *h = dlopen(lname, flags);
98
  if (h == NULL)
99
    {
100
      const char *msg = dlerror();
101
      throw new ::java::lang::UnknownError(JvNewStringLatin1(msg));
102
    }
103
  handler = (gnu::gcj::RawData*) h;
104
#else
105
  const char *msg
106
    = "shared library class loading is not supported on this platform";
107
  throw new ::java::lang::UnsupportedOperationException(JvNewStringLatin1(msg));
108
#endif
109
}
110
 
111
jboolean
112
gnu::gcj::runtime::SharedLibHelper::hasResource (jstring name)
113
{
114
#ifdef HAVE_DLOPEN
115
  _Jv_core_chain *node = _Jv_FindCore ((_Jv_core_chain *) core_chain, name);
116
  return node != NULL;
117
#else
118
  return false;
119
#endif
120
}
121
 
122
#ifdef HAVE_DLOPEN
123
extern gnu::gcj::Core *_Jv_create_core (_Jv_core_chain *node, jstring name);
124
#endif
125
 
126
gnu::gcj::Core *
127
gnu::gcj::runtime::SharedLibHelper::findCore (jstring name)
128
{
129
#ifdef HAVE_DLOPEN
130
  ensureInit();
131
  return _Jv_create_core ((_Jv_core_chain *) core_chain, name);
132
#else
133
  return NULL;
134
#endif
135
}
136
 
137
void
138
gnu::gcj::runtime::SharedLibHelper::finalize()
139
{
140
  _Jv_FreeCoreChain ((_Jv_core_chain *) core_chain);
141
#ifdef HAVE_DLOPEN
142
  if (handler)
143
    dlclose (handler);
144
#endif
145
}
146
 
147
void
148
gnu::gcj::runtime::SharedLibHelper::ensureSupersLinked(jclass k)
149
{
150
  _Jv_Linker::wait_for_state (k, JV_STATE_LOADING);
151
}

powered by: WebSVN 2.1.0

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