[go: up one dir, main page]

File: gc_none.c

package info (click to toggle)
sablevm 1.11.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,980 kB
  • ctags: 7,922
  • sloc: ansic: 116,013; sh: 8,679; makefile: 489
file content (108 lines) | stat: -rw-r--r-- 2,538 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This source file is part of SableVM.                            *
 *                                                                 *
 * See the file "LICENSE" for the copyright information and for    *
 * the terms and conditions for copying, distribution and          *
 * modification of this source file.                               *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#if defined (_SABLEVM_NO_GC)

/*
----------------------------------------------------------------------
_svmf_heap_init_defaults
----------------------------------------------------------------------
*/

svm_static void
_svmf_heap_init_defaults (_svmt_JavaVM *vm)
{
  vm->heap.size = SVM_HEAP_DEFAULT_SIZE;
}

/*
----------------------------------------------------------------------
_svmf_heap_init
----------------------------------------------------------------------
*/

svm_static jint
_svmf_heap_init (_svmt_JNIEnv *env)
{
  _svmt_JavaVM *vm = env->vm;

  if (vm->verbose_gc)
    {
      _svmf_printf (env, stderr,
		    "[verbose gc: allocating heap of %d bytes]\n",
		    vm->heap.size);
    }

  /* allocate heap */
  vm->heap.start = _svmf_malloc (vm->heap.size);

  if (vm->heap.start == NULL)
    {
      return JNI_ERR;
    }

  vm->heap.end = ((char *) vm->heap.start) + vm->heap.size;
  vm->heap.alloc = vm->heap.start;
  vm->heap.hashcode_base = 0 - (size_t) vm->heap.start;

  return JNI_OK;
}

/*
----------------------------------------------------------------------
_svmf_gc_new_instance
----------------------------------------------------------------------
*/

svm_static jint
_svmf_gc_new_instance (_svmt_JNIEnv *env, size_t instance_size,
		       void **pinstance)
{
  _svmt_JavaVM *vm = env->vm;
  void *result = NULL;
  jint status = JNI_OK;

  _svmm_mutex_lock (vm->global_mutex);

  _svmf_halt_if_requested (env);

  if (instance_size <=
      (size_t) (((char *) vm->heap.end) - ((char *) vm->heap.alloc)))
    {
      result = vm->heap.alloc;
      vm->heap.alloc = ((char *) vm->heap.alloc) + instance_size;
    }
  else
    {
      /* no gc means we're out of memory... */
      status = JNI_ERR;
    }

  _svmm_mutex_unlock ();

  if (status != JNI_OK)
    {
      _svmf_error_OutOfMemoryError (env);
      return JNI_ERR;
    }

  {
    size_t i;

    for (i = 0; i < instance_size; i++)
      {
	((char *) result)[i] = 0;
      }
  }

  *pinstance = result;

  return JNI_OK;
}

#endif /* defined (_SABLEVM_NO_GC) */