This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sewbacca's profile picture

Java heap space error

Started by Sewbacca, 09 March 2016 - 08:45 PM
Sewbacca #1
Posted 09 March 2016 - 09:45 PM
What does mean the Java heap space error?
Lyqyd #2
Posted 09 March 2016 - 10:21 PM
Post your code and the full error message. But I suspect that reading the sticky posts would answer your question.
Sewbacca #3
Posted 09 March 2016 - 10:27 PM

input = loadstring('LuaQ  		,   6    !   E  F      @  	 A \   H   E  F     @ @      E  F     @    D  ^    A @\  	   _G    type    string    open    r    table    nil    error    "Expected file name or file handle				 ')
				  output = loadstring('LuaQ  		?  ?    !   E  F      @  	 A \   H   E  F     @ @      E  F     @    D  ^    A @\  	   _G    type    string    open    w    table    nil    error    "Expected file name or file handle				 ')
					type = loadstring('LuaQ  		?  ?       E  F       @ @ A@F   Z    ^ @   ^  C  ^        _G    type    table    bFileHandle    bClosed    closed file    file				 ')
			 close = loadstring('LuaQ  		$   &      @[     D  K @\        close				 ')
  write = loadstring('LuaQ  		?  ?       E  \  K   ? ]   ^        output    write				 ')
	flush = loadstring('LuaQ  		(   *         @  @        flush				 ')
lines = loadstring('LuaQ  		8   >          E	 @A \  K  ]   ^    D  K  ]   ^        open    r    lines				 ')
	 read = loadstring('LuaQ  		?  ?       E  \  K   ? ]   ^        input    read				 ')
	open = loadstring('LuaQ  		@   ?    S  ?     @ @? ?   @ ? @? @  @ @ A\nA ?I  d  ÁA   Ad  ?A   d  ?A  ' .. string.char(13) .. '@B @B@ A\nA ?I  d  ÁA  d  ?A  Ad  ?A  C \nA ?I d  ÁA  d  ?A  C @D @ A\nA ?I d  ÁA  Ad  ?A  d  ?A   A  A A A        r    fs    open    bFileHandle    bClosed     close    read    lines    w    a    write    flush    rb    wb    ab    error    Unsupported mode		   K   N       D  F  \	      close    bClosed 					   O   Y      ?     A@     ? ? ?  ?@@    ? ? ?  ?   ?A @? Á  ?       *l 	readLine    *a    readAll    error    Unsupported format						Z   c       d   	  ^  	   	   [   b         @    @@    D  F  \  DA I       	readLine     close    bClosed 								   i   l       D  F  \	      close    bClosed 					   m   o       ?@ ?  @?       write						p   r       D  F  \        flush						y   |       D  F  \	      close    bClosed 					   }          D  F  ]   ^        read						?  ?       D  F  \	      close    bClosed 					   ?  ?       ?@ ?  @?       write						?  ?       D  F  \        flush							 ')
																									

and the error message:

Java heap space
Goodby

The computer shutdown

The functions are loaded strings (loadstring(dumped string)), the file was loaded with os.loadAPI()
Edited on 09 March 2016 - 09:30 PM
Bomb Bloke #4
Posted 10 March 2016 - 01:28 AM
Some rather obvious questions come to mind. Can you answer them before they're asked?
Sewbacca #5
Posted 10 March 2016 - 07:38 AM
Okay, I think you want the code behind my previous posted code:


function formatEntry(_fName, _sFunction)
  return _fName .. " = loadstring('" .. _sFunction:gsub("\\n", "\\\\n"):gsub("\n", "\\n"):gsub(string.char(13), "' .. string.char(13) .. '")  .. "')\n"
end
os["exportAPI"] = function(_tAPI, _sPath)
  local fileAPI = io.open(_sPath, "a")
  for key, value in pairs(_tAPI) do
  fileAPI:write(try(formatEntry, key, try(string.dump, value)))
  end
  fileAPI:close()
end
-- lua> os.exportAPI(io, "/copyIO")
-- lua> os.loadAPI("/copyIO")
-- Java heap space
-- Goodby
Edited on 10 March 2016 - 06:39 AM
SquidDev #6
Posted 10 March 2016 - 11:39 AM
You're trying to save a binary string. CC doesn't like that and so loading it produces garbage. You'll have to escape the string to prevent encoding issues (either by using escape codes (such as "\13") or base64 encoding it). Or find another way to do what you're trying to do: I guarantee there is a better way.
Edited on 10 March 2016 - 10:40 AM
Sewbacca #7
Posted 10 March 2016 - 04:06 PM
Or find another way to do what you're trying to do: I guarantee there is a better way.

Can you explain please the "other way"?
SquidDev #8
Posted 10 March 2016 - 04:43 PM
Or find another way to do what you're trying to do: I guarantee there is a better way.

Can you explain please the "other way"?

I don't know what you are trying to do: why are you dumping functions and trying to load them again? Most functions cannot be serialized this way as they use upvalues, so if you could load these functions they wouldn't work correctly.
Edited on 10 March 2016 - 03:45 PM
Sewbacca #9
Posted 10 March 2016 - 06:21 PM
Okay, I want save functions in files.
Edited on 10 March 2016 - 05:22 PM
KingofGamesYami #10
Posted 10 March 2016 - 07:07 PM
Okay, I want save functions in files.

SquidDev wants to know your end goal. Taking functions that were loaded from a file and placing them in a file is fairly useless. Just copy the original text / code.
Sewbacca #11
Posted 10 March 2016 - 09:49 PM
Yes, but if you want to modify functions of an api, save it into a file and you don't have the code, you can use os.exportAPI.
KingofGamesYami #12
Posted 10 March 2016 - 10:52 PM
Yes, but if you want to modify functions of an api, save it into a file and you don't have the code, you can use os.exportAPI.

What you want to do is impossible. If you want to modify the behavior of a function, you should just override the function.

Technically you can save the string.dump'd function to a file, and edit that, but that's not human-readable. Also, it breaks for anything using a value not defined in the function parameters.

Also, CC provides all the source code in either ROM or BIOS.lua. Anything not found there is written in Java.

The io library, for example, is located at rom/apis/io.
Edited on 10 March 2016 - 09:52 PM
Sewbacca #13
Posted 11 March 2016 - 01:17 PM
The io library, for example, is located at rom/apis/io.

This was only a test, and I didn't want a human readable file.
To modify functions was a example, a very bad I think, so:

Yes, but if you want to save functions of an api into a file and you don't have the code, you can use os.exportAPI.
Edited on 11 March 2016 - 12:19 PM
KingofGamesYami #14
Posted 11 March 2016 - 01:30 PM
But what would be the point of saving functions to a file in a non-human-readable format? What are you going to do with those functions?

Also, I'm fairly certain you will always have the code. To use code, you must have access to said code. The API's source code is somewhere, and you can always copy that.

TL;DR: You're doing it wrong. os.exportAPI is pretty much impossible.
Sewbacca #15
Posted 11 March 2016 - 02:50 PM
You can compile programs or apis without giving the code.
KingofGamesYami #16
Posted 11 March 2016 - 03:14 PM
Yes, but that's what string.dump gives you. compiled code.
Lupus590 #17
Posted 11 March 2016 - 05:19 PM
If you want the source from compiled code you will be needing a decompiler, be warned that this wont decompile functions which have been defined in Java (such as most of the OS/FS/Turtle APIs and functions provided by peripherals).
Sewbacca #18
Posted 11 March 2016 - 08:20 PM
Yes, but that's what string.dump gives you. compiled code.

Okay, so how can I save functions, when I don't have the code? After a reboot of the computer is the api unloaded. String.dump is the only way I think.
Edited on 11 March 2016 - 07:21 PM
hbomb79 #19
Posted 11 March 2016 - 10:11 PM
I really don't understand why you want to.

If you gave us that information then we could likely suggest an alternative. If you want to modify the behaviour of an API then just overwrite that function.

Saving functions is nearly impossible to do perfectly, the save will be fine but loading it back in again will not work most of the time because, as mentioned most will use up-values.

Let us know your absolute end goal and we can suggest an easier, more feasible option.
Sewbacca #20
Posted 11 March 2016 - 10:45 PM
Okay, I think I understand the problem, I just wanted to add new functions in the os api, one of these should be an export method, which saves tables with functions into a file.
Edited on 11 March 2016 - 09:46 PM
hbomb79 #21
Posted 11 March 2016 - 11:06 PM
If you want to add a new function to the OS api, just do this in a file that is run everytime the computer starts up (startup):


function os["YOUR_FUNCTION_NAME"]()
  -- what you want it to do
end
Sewbacca #22
Posted 11 March 2016 - 11:11 PM
No, I wanted to add the function exportAPI, I konw, how I have to add it.
Edited on 11 March 2016 - 10:11 PM
hbomb79 #23
Posted 11 March 2016 - 11:27 PM
why do you want to 'export APIs'? The point I am trying to make.
Sewbacca #24
Posted 15 March 2016 - 05:54 PM
Maybe this topic has an example: http://www.computerc...__fromsearch__1
Edited on 15 March 2016 - 04:55 PM