Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: Allocator/DefaultHeapAllocator.java


1   // DefaultHeapAllocator.java, created Mon Apr  9  1:01:31 2001 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package Allocator;
5   
6   import Bootstrap.PrimordialClassLoader;
7   import Clazz.jq_Class;
8   import Clazz.jq_StaticMethod;
9   import Memory.Address;
10  import Run_Time.Unsafe;
11  
12  /**
13   * DefaultHeapAllocator
14   * 
15   * @author  John Whaley <jwhaley@alum.mit.edu>
16   * @version $Id: DefaultHeapAllocator.java,v 1.6 2003/05/12 10:04:52 joewhaley Exp $
17   */
18  public abstract class DefaultHeapAllocator {
19  
20      public static final HeapAllocator def() {
21          return Unsafe.getThreadBlock().getNativeThread().getHeapAllocator();
22      }
23      
24      public static final void init() throws OutOfMemoryError {
25          def().init();
26      }
27      public static final Object allocateObject(int size, Object vtable) throws OutOfMemoryError {
28          Unsafe.getThreadBlock().disableThreadSwitch();
29          Object o = def().allocateObject(size, vtable);
30          Unsafe.getThreadBlock().enableThreadSwitch();
31          return o;
32      }
33      public static final Object allocateObjectAlign8(int size, Object vtable) throws OutOfMemoryError {
34          Unsafe.getThreadBlock().disableThreadSwitch();
35          Object o = def().allocateObjectAlign8(size, vtable);
36          Unsafe.getThreadBlock().enableThreadSwitch();
37          return o;
38      }
39      public static final Object allocateArray(int length, int size, Object vtable)
40      throws OutOfMemoryError, NegativeArraySizeException {
41          Unsafe.getThreadBlock().disableThreadSwitch();
42          Object o = def().allocateArray(length, size, vtable);
43          Unsafe.getThreadBlock().enableThreadSwitch();
44          return o;
45      }
46      public static final Object allocateArrayAlign8(int length, int size, Object vtable)
47      throws OutOfMemoryError, NegativeArraySizeException {
48          Unsafe.getThreadBlock().disableThreadSwitch();
49          Object o = def().allocateArrayAlign8(length, size, vtable);
50          Unsafe.getThreadBlock().enableThreadSwitch();
51          return o;
52      }
53      public static final int freeMemory() { return def().freeMemory(); }
54      public static final int totalMemory() { return def().totalMemory(); }
55  
56      public static final void collect() {
57          Unsafe.getThreadBlock().disableThreadSwitch();
58          def().collect();
59          Unsafe.getThreadBlock().enableThreadSwitch();
60      }
61      
62      public static final void processPtrField(Address a) {
63          def().processPtrField(a);
64      }
65  
66      public static final jq_StaticMethod _allocateObject;
67      public static final jq_StaticMethod _allocateObjectAlign8;
68      public static final jq_StaticMethod _allocateArray;
69      public static final jq_StaticMethod _allocateArrayAlign8;
70      static {
71          jq_Class k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("LAllocator/DefaultHeapAllocator;");
72          _allocateObject = k.getOrCreateStaticMethod("allocateObject", "(ILjava/lang/Object;)Ljava/lang/Object;");
73          _allocateObjectAlign8 = k.getOrCreateStaticMethod("allocateObjectAlign8", "(ILjava/lang/Object;)Ljava/lang/Object;");
74          _allocateArray = k.getOrCreateStaticMethod("allocateArray", "(IILjava/lang/Object;)Ljava/lang/Object;");
75          _allocateArrayAlign8 = k.getOrCreateStaticMethod("allocateArrayAlign8", "(IILjava/lang/Object;)Ljava/lang/Object;");
76      }
77  }