Check-in [1fab29f14a]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Load the class binary data; Base for exceptions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1fab29f14a5f936b946b8d3e29524606f918b1f0
User & Date: stephanie.gawroriski 2019-01-12 01:09:34
Context
2019-01-12
01:18
Base for class processing. check-in: 1a2220c9d7 user: stephanie.gawroriski tags: trunk
01:09
Load the class binary data; Base for exceptions. check-in: 1fab29f14a user: stephanie.gawroriski tags: trunk
2019-01-11
08:02
Backup developer notes. check-in: 2bfb68e48c user: squirreljme tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/ClassLoader.java.

7
8
9
10
11
12
13

14


15
16
17
18


19
20
21
22
23
24
25
..
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

// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

import cc.squirreljme.vm.VMClassLibrary;

import cc.squirreljme.vm.VMSuiteManager;


import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;


import net.multiphasicapps.classfile.ClassName;
import net.multiphasicapps.scrf.RegisterClass;

/**
 * This is a class loader which manages and can cache multiple classes.
 *
 * @since 2019/01/05
................................................................................
	
	/**
	 * Loads the given class.
	 *
	 * @param __n The class to load.
	 * @return The loaded class.
	 * @throws NullPointerException On null arguments.

	 * @since 2019/01/06
	 */
	public final LoadedClass loadClass(String __n)
		throws NullPointerException
	{
		if (__n == null)
			throw new NullPointerException("NARG");
		
		return this.loadClass(new ClassName(__n));
	}
	
	/**
	 * Loads the given class.
	 *
	 * @param __n The class to load.
	 * @return The loaded class.
	 * @throws NullPointerException On null arguments.

	 * @since 2019/01/10
	 */
	public final LoadedClass loadClass(ClassName __n)
		throws NullPointerException
	{
		if (__n == null)
			throw new NullPointerException("NARG");
		






























































		throw new todo.TODO();
	}
}









>

>
>




>
>







 







>



|













>



|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
>
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
..
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

import cc.squirreljme.vm.VMClassLibrary;
import cc.squirreljme.vm.VMException;
import cc.squirreljme.vm.VMSuiteManager;
import java.io.InputStream;
import java.io.IOException;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import net.multiphasicapps.classfile.InvalidClassFormatException;
import net.multiphasicapps.classfile.ClassFile;
import net.multiphasicapps.classfile.ClassName;
import net.multiphasicapps.scrf.RegisterClass;

/**
 * This is a class loader which manages and can cache multiple classes.
 *
 * @since 2019/01/05
................................................................................
	
	/**
	 * Loads the given class.
	 *
	 * @param __n The class to load.
	 * @return The loaded class.
	 * @throws NullPointerException On null arguments.
	 * @throws VMClassNotFoundException If the class was not found.
	 * @since 2019/01/06
	 */
	public final LoadedClass loadClass(String __n)
		throws NullPointerException, VMClassNotFoundException
	{
		if (__n == null)
			throw new NullPointerException("NARG");
		
		return this.loadClass(new ClassName(__n));
	}
	
	/**
	 * Loads the given class.
	 *
	 * @param __n The class to load.
	 * @return The loaded class.
	 * @throws NullPointerException On null arguments.
	 * @throws VMClassNotFoundException If the class was not found.
	 * @since 2019/01/10
	 */
	public final LoadedClass loadClass(ClassName __n)
		throws NullPointerException, VMClassNotFoundException
	{
		if (__n == null)
			throw new NullPointerException("NARG");
		
		// Lock on self as new classes are loaded
		synchronized (this)
		{
			// If the class has already been loaded use that one
			Map<ClassName, LoadedClass> classes = this._classes;
			LoadedClass rv = classes.get(__n);
			if (rv != null)
				return rv;
			
			// If this is a primitive type or array then it is a special thing
			// and will not be in a resource
			ClassFile cf;
			VMClassLibrary inlib;
			if (__n.isPrimitive() || __n.isArray())
			{
				cf = ClassFile.special(__n.field());
				inlib = null;
			}
			
			// Load class from resource instead
			else
			{
				// This is the class that is read, in binary form
				String fileform = __n.toString() + ".class";
				
				// Go through our classpath looking for this class in its
				// resource format
				cf = null;
				inlib = null;
				for (VMClassLibrary b : this._classpath)
					try (InputStream in = b.resourceAsStream(fileform))
					{
						// Not found
						if (in == null)
							continue;
						
						// Load it
						cf = ClassFile.decode(in);
						inlib = b;
						
						// Stop
						break;
					}
					catch (InvalidClassFormatException e)
					{
						// {@squirreljme.error AE05 The class is not formatted
						// correctly. (The class name)}
						throw new VMException("AE05 " + __n, e);
					}
					catch (IOException e)
					{
						// {@squirreljme.error AE04 Read error trying to read
						// the class file. (The class)}
						throw new VMException("AE04 " + __n, e);
					}
				
				// {@squirreljme.error AE03 Could not find the specified class.
				// (The name of the class)}
				if (cf == null || inlib == null)
					throw new VMClassNotFoundException("AE03 " + __n);
			}
			
			throw new todo.TODO();
		}
	}
}

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/VMClassNotFoundException.java.

































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
//     Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

/**
 * This is thrown when the specified class was not found.
 *
 * @since 2019/01/11
 */
public class VMClassNotFoundException
	extends VMRuntimeException
{
	/**
	 * Initialize the exception with no message or cause.
	 *
	 * @since 2019/01/11
	 */
	public VMClassNotFoundException()
	{
	}
	
	/**
	 * Initialize the exception with a message and no cause.
	 *
	 * @param __m The message.
	 * @since 2019/01/11
	 */
	public VMClassNotFoundException(String __m)
	{
		super(__m);
	}
	
	/**
	 * Initialize the exception with a message and cause.
	 *
	 * @param __m The message.
	 * @param __c The cause.
	 * @since 2019/01/11
	 */
	public VMClassNotFoundException(String __m, Throwable __c)
	{
		super(__m, __c);
	}
	
	/**
	 * Initialize the exception with no message and with a cause.
	 *
	 * @param __c The cause.
	 * @since 2019/01/11
	 */
	public VMClassNotFoundException(Throwable __c)
	{
		super(__c);
	}
}

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/VMRuntimeException.java.







































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
//     Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

import cc.squirreljme.vm.VMException;

/**
 * This is an exception in SummerCoat which is translated to an exception
 * for the virtual machine itself when it has a chance to do so.
 *
 * @since 2019/01/11
 */
public class VMRuntimeException
	extends VMException
{
	/**
	 * Initialize the exception with no message or cause.
	 *
	 * @since 2019/01/11
	 */
	public VMRuntimeException()
	{
	}
	
	/**
	 * Initialize the exception with a message and no cause.
	 *
	 * @param __m The message.
	 * @since 2019/01/11
	 */
	public VMRuntimeException(String __m)
	{
		super(__m);
	}
	
	/**
	 * Initialize the exception with a message and cause.
	 *
	 * @param __m The message.
	 * @param __c The cause.
	 * @since 2019/01/11
	 */
	public VMRuntimeException(String __m, Throwable __c)
	{
		super(__m, __c);
	}
	
	/**
	 * Initialize the exception with no message and with a cause.
	 *
	 * @param __c The cause.
	 * @since 2019/01/11
	 */
	public VMRuntimeException(Throwable __c)
	{
		super(__c);
	}
}