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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [gcj/] [natCore.cc] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
// natCore -- C++ side of Core
2
 
3
/* Copyright (C) 2001, 2002, 2003, 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: Anthony Green <green@redhat.com>.  */
12
 
13
#include <config.h>
14
 
15
#include <gcj/cni.h>
16
#include <jvm.h>
17
#include <string.h>
18
#include <stdlib.h>
19
 
20
#include <java/lang/NullPointerException.h>
21
#include <java/io/IOException.h>
22
#include <gnu/gcj/Core.h>
23
 
24
// List of global core values.
25
static _Jv_core_chain *root;
26
 
27
static void
28
default_register_resource (_Jv_core_chain *node)
29
{
30
  node->next = root;
31
  root = node;
32
}
33
 
34
// This is set only when a lock is held on java.lang.Class.
35
// This function is called to handle a new core node.
36
void (*_Jv_RegisterCoreHook) (_Jv_core_chain *) = default_register_resource;
37
 
38
void
39
_Jv_RegisterResource (void *vptr)
40
{
41
  char *rptr = (char *) vptr;
42
 
43
  _Jv_core_chain *cc = (_Jv_core_chain *) _Jv_Malloc (sizeof (_Jv_core_chain));
44
 
45
  cc->name_length = ((int *)rptr)[0];
46
  cc->data_length = ((int *)rptr)[1];
47
  cc->name = rptr + 2 * sizeof (int);
48
  cc->data = cc->name + cc->name_length;
49
  cc->next = NULL;
50
 
51
  (*_Jv_RegisterCoreHook) (cc);
52
}
53
 
54
void
55
_Jv_FreeCoreChain (_Jv_core_chain *chain)
56
{
57
  while (chain != NULL)
58
    {
59
      _Jv_core_chain *next = chain->next;
60
      _Jv_Free (chain);
61
      chain = next;
62
    }
63
}
64
 
65
_Jv_core_chain *
66
_Jv_FindCore (_Jv_core_chain *node, jstring name)
67
{
68
  char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (name) + 1);
69
  jsize total = JvGetStringUTFRegion (name, 0, name->length(), buf);
70
  buf[total] = '\0';
71
 
72
  // Usually requests here end up as an absolute URL.  We strip the
73
  // initial `/'.
74
  if (buf[0] == '/')
75
    {
76
      ++buf;
77
      --total;
78
    }
79
 
80
  while (node)
81
    {
82
      if (total == node->name_length
83
          && strncmp (buf, node->name, total) == 0)
84
        return node;
85
      node = node->next;
86
    }
87
 
88
  return NULL;
89
}
90
 
91
gnu::gcj::Core *
92
_Jv_create_core (_Jv_core_chain *node, jstring name)
93
{
94
  node = _Jv_FindCore (node, name);
95
 
96
  gnu::gcj::Core *core = NULL;
97
  if (node)
98
    {
99
      core = new gnu::gcj::Core ();
100
      core->ptr = (gnu::gcj::RawData *) node->data;
101
      core->length = node->data_length;
102
    }
103
  return core;
104
}
105
 
106
gnu::gcj::Core *
107
gnu::gcj::Core::find (jstring name)
108
{
109
  gnu::gcj::Core *core = _Jv_create_core (root, name);
110
  return core;
111
}
112
 
113
gnu::gcj::Core *
114
gnu::gcj::Core::create (jstring name)
115
{
116
  gnu::gcj::Core *core = _Jv_create_core (root, name);
117
  if (core == NULL)
118
    throw new ::java::io::IOException (JvNewStringLatin1 ("can't open core"));
119
  return core;
120
}

powered by: WebSVN 2.1.0

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