Check-in [b5598278dd]

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

Overview
Comment:Correct bug in the allocator where free chunks were only marked used when they had to be split.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b5598278ddebd02c4fb72f7725a44a6a0bae1c15
User & Date: stephanie.gawroriski 2019-06-16 14:23:54
Context
2019-06-16
15:27
Remove extra C file. check-in: 7413ca5b27 user: stephanie.gawroriski tags: trunk
14:23
Correct bug in the allocator where free chunks were only marked used when they had to be split. check-in: b5598278dd user: stephanie.gawroriski tags: trunk
14:12
Add print of static field pointer; Clear the percent flag so that formatted strings are printed correctly. check-in: c249eafd1f user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/klib/supervisor/cc/squirreljme/jvm/Allocator.java.

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101




102
103
104
105
106
107
108
...
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
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
					Assembly.memWriteInt(nextseek, CHUNK_SIZE_OFFSET,
						(csz - want) | MEMPART_FREE_BIT);
					
					// The next chunk is the next the chunk we claimed
					Assembly.memWriteInt(nextseek, CHUNK_NEXT_OFFSET,
						cnx);
					
					// The size of our current chunk is the wanted size
					Assembly.memWriteInt(seeker, CHUNK_SIZE_OFFSET,
						want);
					
					// The next chunk of the current chunk is the new chunk
					Assembly.memWriteInt(seeker, CHUNK_NEXT_OFFSET,
						nextseek);
				}




				
				// Clear out memory since Java expects the data to be
				// initialized to zero always
				Assembly.sysCallP(SystemCallIndex.MEM_SET, rv, 0, __sz);
				
				// Use this chunk
				return rv;
................................................................................
	 *
	 * @param __p The pointer to free.
	 * @since 2019/05/27
	 */
	static final void free(int __p)
	{
		if (__p == 0 || __p == Constants.BAD_MAGIC)
		{
			Assembly.breakpoint();
			throw new VirtualMachineError();
		}
		
		// Determine the seeker position for this chunk
		int seeker = __p - CHUNK_LENGTH;
		
		// Read chunk properties
		int csz = Assembly.memReadInt(seeker, CHUNK_SIZE_OFFSET),
			cnx = Assembly.memReadInt(seeker, CHUNK_NEXT_OFFSET);
		








		// Parameters used for memory corruption
		int i = CHUNK_LENGTH,
			bm = Constants.BAD_MAGIC,
			rci = CHUNK_LENGTH + Constants.OBJECT_COUNT_OFFSET;
		
		// Corrupt anything up to the reference count index
		for (; i < rci; i+= 4)
................................................................................
			Assembly.memWriteInt(seeker, i, 0);
			i += 4;
		}
		
		// Then just wipe the remaining memory
		for (; i < csz; i+= 4)
			Assembly.memWriteInt(seeker, i, bm);
		
		// Set as free
		Assembly.memWriteInt(seeker, CHUNK_SIZE_OFFSET,
			csz | MEMPART_FREE_BIT);
	}
	
	/**
	 * Initializes the RAM links.
	 *
	 * @param __rambase The base of RAM.
	 * @param __ramsize The amount of RAM available.







<
<
<
<




>
>
>
>







 







<

<
<








>
>
>
>
>
>
>
>







 







<
<
<
<







87
88
89
90
91
92
93




94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
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
...
158
159
160
161
162
163
164




165
166
167
168
169
170
171
					Assembly.memWriteInt(nextseek, CHUNK_SIZE_OFFSET,
						(csz - want) | MEMPART_FREE_BIT);
					
					// The next chunk is the next the chunk we claimed
					Assembly.memWriteInt(nextseek, CHUNK_NEXT_OFFSET,
						cnx);
					




					// The next chunk of the current chunk is the new chunk
					Assembly.memWriteInt(seeker, CHUNK_NEXT_OFFSET,
						nextseek);
				}
				
				// The size of our current chunk is the wanted size
				Assembly.memWriteInt(seeker, CHUNK_SIZE_OFFSET,
					want);
				
				// Clear out memory since Java expects the data to be
				// initialized to zero always
				Assembly.sysCallP(SystemCallIndex.MEM_SET, rv, 0, __sz);
				
				// Use this chunk
				return rv;
................................................................................
	 *
	 * @param __p The pointer to free.
	 * @since 2019/05/27
	 */
	static final void free(int __p)
	{
		if (__p == 0 || __p == Constants.BAD_MAGIC)

			Assembly.breakpoint();


		
		// Determine the seeker position for this chunk
		int seeker = __p - CHUNK_LENGTH;
		
		// Read chunk properties
		int csz = Assembly.memReadInt(seeker, CHUNK_SIZE_OFFSET),
			cnx = Assembly.memReadInt(seeker, CHUNK_NEXT_OFFSET);
		
		// Bad size?
		if (csz <= 0)
			Assembly.breakpoint();
		
		// Set as free
		Assembly.memWriteInt(seeker, CHUNK_SIZE_OFFSET,
			csz | MEMPART_FREE_BIT);
		
		// Parameters used for memory corruption
		int i = CHUNK_LENGTH,
			bm = Constants.BAD_MAGIC,
			rci = CHUNK_LENGTH + Constants.OBJECT_COUNT_OFFSET;
		
		// Corrupt anything up to the reference count index
		for (; i < rci; i+= 4)
................................................................................
			Assembly.memWriteInt(seeker, i, 0);
			i += 4;
		}
		
		// Then just wipe the remaining memory
		for (; i < csz; i+= 4)
			Assembly.memWriteInt(seeker, i, bm);




	}
	
	/**
	 * Initializes the RAM links.
	 *
	 * @param __rambase The base of RAM.
	 * @param __ramsize The amount of RAM available.