View unanswered posts | View active topics It is currently Sat Apr 19, 2014 6:08 am






Reply to topic  [ 10 posts ] 
Error : Invalid address update & Constant pool overflow 
Author Message
Rookie
User avatar

Joined: Thu Feb 23, 2012 6:24 pm
Posts: 6
Post Error : Invalid address update & Constant pool overflow
Hi all,

I have been using ROBOTC for some time now, but I have two errors with my code that I do not seem to be able to fix. Any help would be appreciated.

First, I need to explain the situation. My ROBOTC programs are quite complex and can easily go beyond 10k lines. The reason is that I have been developing a neural architecture IDE (in Java) that creates C code adapted for a K3, a virtual world or a NXT. Since I need to log all the information while the robot is running, I have created a fprintf function for the ROBOTC. The ROBOTC fprintf function allows to send and string and some int parameters to a computer via bluetooth, and the PC logs it in files.

Since a string cannot be more than 20 characters long (for some reason), I have adapted the Java neural-arch IDE to chunks the strings in order to have multiple calls to my function fprintf with smaller strings. And that brings me to my problem (at last !).

Since my fprintf is called (VERY) often in the program, at one point it gives me : **Error**:Constant pool overflow. So at one point I decided to reduce the amount of calls to the fprintf function, which then gave me : **Error** : Invalid address update FROM '0x..' to '0x1..'.

I know my programs are quite long, but the way I see it is that I do not declare variables except at the beginning of the program. So why is it that at one point in the code, ROBOTC throws me those errors ?

Here is a sample of my fprintf function, if that can be of any help.

Code:
void fprintf(string fileType, string messageToSend, int param1 = -1000, int param2 = -1000, int param3 = -1000, int param4 = -1000, int param5 = -1000, int param6 = -1000, int param7 = -1000, int param8 = -1000, int param9 = -1000, int param10 = -1000) {
   ...
   // Send via BT
   ...

   return;
}


Thanks and hopefully this won't be a rookie question !


Thu Feb 23, 2012 6:51 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: Error : Invalid address update & Constant pool overflow
Would you mind trying out something for me? To try an eliminate the parameter pre-initailisation as a possible cause of the error I made a couple of function overloads for your fprintf function.
Can you see if this works better?
Code:
void fprintf(string fileType, string messageToSend, int param1, int param2, int param3, int param4,
  int param5, int param6, int param7, int param8, int param9, int param10) {
  // your original function goes here without the pre-initialisation
   return;
}

void fprintf(string fileType, string messageToSend)
{
  fprintf(fileType, messageToSend, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000);
}

void fprintf(string fileType, string messageToSend, int param1)
{
  fprintf(fileType, messageToSend, param1, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000);   
}
   
void fprintf(string fileType, string messageToSend, int param1, int param2)
{
  fprintf(fileType, messageToSend, param1, param2, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000);
}

void fprintf(string fileType, string messageToSend, int param1, int param2, int param3) {
  fprintf(fileType, messageToSend, param1, param2, param3, -1000, -1000, -1000, -1000, -1000, -1000, -1000);   
}   
 
void fprintf(string fileType, string messageToSend, int param1, int param2, int param3, int param4)

  fprintf(fileType, messageToSend, param1, param2, param3, param4, -1000, -1000, -1000, -1000, -1000, -1000);
}

void fprintf(string fileType, string messageToSend, int param1, int param2, int param3, int param4,
  int param5)
{
  fprintf(fileType, messageToSend, param1, param2, param3, param4, param5, -1000, -1000, -1000, -1000, -1000);
}

void fprintf(string fileType, string messageToSend, int param1, int param2, int param3, int param4,
  int param5, int param6)
{
  fprintf(fileType, messageToSend, param1, param2, param3, param4, param5, param6, -1000, -1000, -1000, -1000);
}

void fprintf(string fileType, string messageToSend, int param1, int param2, int param3, int param4,
  int param5, int param6, int param7)
{
  fprintf(fileType, messageToSend, param1, param2, param3, param4, param5, param6, param7, -1000, -1000, -1000);
}

void fprintf(string fileType, string messageToSend, int param1, int param2, int param3, int param4,
  int param5, int param6, int param7, int param8)
{
  fprintf(fileType, messageToSend, param1, param2, param3, param4, param5, param6, param7, param8, -1000, -1000);
}

void fprintf(string fileType, string messageToSend, int param1, int param2, int param3, int param4,
  int param5, int param6, int param7, int param8, int param9)
{
  fprintf(fileType, messageToSend, param1, param2, param3, param4, param5, param6, param7, param8, param9, -1000);
}


- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Feb 24, 2012 4:14 am
Profile WWW
Rookie
User avatar

Joined: Thu Feb 23, 2012 6:24 pm
Posts: 6
Post Re: Error : Invalid address update & Constant pool overflow
Hi Guys,

Thanks for the help. Xander, your idea seemed like a good one, but unfortunately it did not change anything. Same errors at the same places.

Here is the assembly+C code generated using the F9 key. I have deleted all the logic inside the original fprintf function, since with or without the logic, the errors are still shown.

Code:
void fprintf(string fileType, string messageToSend, int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) {
//
//Code segment: fprintf(string fileType, string messageToSend, short param1, short param2, short param3, short param4, short param5, short param6, short param7, short param8, short param9, short param10); Procedure: 36
//
   if (bluetoothEnabled == 1) {
      // logic here
0000: FE                       Return()                            // fprintf(string fileType, string messageToSend, short param1, short param2, short param3, short param4, short param5, short param6, short param7, short param8, short param9, short param10)
   }

     return;
//
//Code segment: fprintf(string fileType, string messageToSend); Procedure: 37
//
}

0000: EF002D50072D8C07         G936H(byte) = G966H(byte)           // String assignment
0008: EF002D64072DA007         G946H(byte) = G976H(byte)           // String assignment
0010: 122BBC030218FC           G956 = -1000                       
0017: 122BBD030218FC           G957 = -1000                       
001E: 122BBE030218FC           G958 = -1000                       
0025: 122BBF030218FC           G959 = -1000                       
002C: 122BC0030218FC           G960 = -1000                       
0033: 122BC1030218FC           G961 = -1000                       
003A: 122BC2030218FC           G962 = -1000                       
0041: 122BC3030218FC           G963 = -1000                       
0048: 122BC4030218FC           G964 = -1000                       
004F: 122BC5030218FC           G965 = -1000                       
0056: 1724                     callSub(fprintf)                   
void fprintf(string fileType, string messageToSend)
0058: FE                       Return()                            // fprintf(string fileType, string messageToSend)
{
  fprintf(fileType, messageToSend, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000);
//
//Code segment: fprintf(string fileType, string messageToSend, short param1); Procedure: 38
//
}


The following lines represents a section in the middle of the program that shows the way I use the fprintf function. The first 2 lines are fine, and the next ones starts to throw me the constant pool overflow error.

Code:
fprintf(fp2,"ne.ncs =-\n");      // no error
fprintf(fp2,"   SOMMAIRE\n");      // no error. the following lines will throw the constant pool overflow error...
fprintf(fp2,"      calculPostPotent");
fprintf(fp2,"ielSynaptique    : ");
fprintf(fp2,"%d (calculé en pr",noN[2].calculPostPotentielSynaptique);
fprintf(fp2,"é-traitement)\n");
fprintf(fp2,"      courantFuite            ");
fprintf(fp2,"   : %d\n",noN[2].courantFuite);


Any ideas ?


Fri Feb 24, 2012 5:21 pm
Profile
Rookie
User avatar

Joined: Thu Feb 23, 2012 6:24 pm
Posts: 6
Post Re: Error : Invalid address update & Constant pool overflow
Humm... perhaps this can help you MIki ?

Code:
      fprintf(fp2,"   SOMMAIRE\n");
32E2: EF002D28082D5A00         G1044H(byte) = G45H(byte)           // String assignment
32EA: EF002D3C0832740C         G1054H(byte) = "\tSOMMAIRE\n"       // String assignment
32F2: 1725                     callSub(fprintf)                   
      fprintf(fp2,"      calculPostPotent");
**Error**:Constant pool overflow
32F4: EF002D28082D5A00         G1044H(byte) = G45H(byte)           // String assignment
32FC: EF002D3C0832FFFF         G1054H(byte) = "\t\tcalculPostPotent" // String assignment
3304: 1725                     callSub(fprintf)                   
      fprintf(fp2,"ielSynaptique    : ");
**Error**:Constant pool overflow
3306: EF002D28082D5A00         G1044H(byte) = G45H(byte)           // String assignment
330E: EF002D3C0832FFFF         G1054H(byte) = "ielSynaptique \t: " // String assignment
3316: 1725                     callSub(fprintf)                   
      fprintf(fp2,"%d (calculé en pr",noN[2].calculPostPotentielSynaptique);
**Error**:Constant pool overflow


Fri Feb 24, 2012 5:35 pm
Profile
Rookie
User avatar

Joined: Thu Feb 23, 2012 6:24 pm
Posts: 6
Post Re: Error : Invalid address update & Constant pool overflow
Hi Miki,

Actually it's phpBB (the forum) that transformed by \t by several spaces. All my strings are maximum 19 bytes(characters).

I have found that if I take the last correct line : fprintf(fp2," SOMMAIRE\n"); and shorten it to fprintf(fp2," SOME\n");, then the following line is fine and the overflow error starts the line after. It's like the string is assigned in memory, but not freed so it runs out of free space.

For example:
Code:
fprintf(fp2, "12345"); // Takes 5 bytes in memory
fprintf(fp2, "12345"); // Takes another 5 bytes
fprintf(fp2, "12345"); // Takes another 5 bytes


So eventually the memory runs out. I am no guru in compilers, but shouldn't the "12345" memory be freed when no longer referenced.

All the above is just an hypothesis though... any ideas ? (and thanks for helping)


Sat Feb 25, 2012 4:53 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: Error : Invalid address update & Constant pool overflow
Did you report this problem to support@robotc.net? The guy who writes the compiler might be able to give you more insight.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Feb 25, 2012 4:58 pm
Profile WWW
Rookie
User avatar

Joined: Thu Feb 23, 2012 6:24 pm
Posts: 6
Post Re: Error : Invalid address update & Constant pool overflow
Thanks Xander and Miki,

I'll email the support at once and keep you posted if a solution comes up.

Frederic


Sat Feb 25, 2012 8:34 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post Re: Error : Invalid address update & Constant pool overflow
"Constant Pool Overflow" error is the following.

The "Constant Pool" is the list of all constant values declared in a program. This includes all character string constants and all numerical floating point constants. I believe the upper limit on the size on the NXT is 3000 bytes. When you use the F9 function to display assembler code you should see the constant pool displayed; I think it is just before the code for the main task.

The reason there's a limit on the constant pool size, rather than as large as flash, is two-fold. ROBOTC runs on many platforms including two that use Harvard architectures (separate address space for RAM and program space); most (all?) Harvard architectures have instructions that can seamlessly read from RAM or flash. And the C-language has no support for Harvard architecture. So the solution is to use flash to store constant values but copy them to RAM when program starts because variables are only supported in RAM. For example, this is what GCC compiler does for the Atmel AVR CPUs. This is the approach used by ROBOTC.

The second reason is that ROBOTC currently supports 16-bit pointers. And conveniently on all the current platforms RAM is limited to 64K (i.e. 16 bit addresses) and can be mapped into the first 64K of address space. The NXT CPU does not use a Harvard architecture -- i.e. single address space for both RAM and Flash. Result is that constant pool needs to be copied to RAM.

And third reason is that user programs are directly executed from flash memory and are stored in the NXT's in-flash file system where they can be located at any address. So, the compiler cannot use absolute flash addresses for constants because they are not absolute. And there cannot be a "relocatable program address fixup function" on "program loading" because the "fixup" wants to rewrite instructions at program "load time" to the valid address. This is the technique used in systems like LINUX and WINDOWS where programs are first copied from file system to RAM and then the "fixup" is applied when final address "binding" is performed.

So, if your problem is that you've exceeded the constant pool size then there's no good result for you but to reduce it.

What I'd suggest is that you examine your disassembly and see if this is the case. It could also be that you've encountered a compiler bug. For fastest response, post further comments here and also send me a email at dickswan@sbcglobal.net.


Wed Feb 29, 2012 10:20 am
Profile
Rookie
User avatar

Joined: Thu Feb 23, 2012 6:24 pm
Posts: 6
Post Re: Error : Invalid address update & Constant pool overflow
Thanks for the answer, I'll look into it and find some other way to do my logging if it's not a compiler bug. Too bad for the limit though...


Wed Feb 29, 2012 11:05 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post Re: Error : Invalid address update & Constant pool overflow
miki wrote:
Now I understand better some indications of the compiler ;-)
Miki.

Regarding the unreferenced variables. The intent is that unreferenced functions are not actually included in the file downloaded to the robot. A few years back this was "disabled" (AKA as "broken") but I recall fixing that.

Regarding "string" size limit of 19 printable characters. Historically the limit is the maximum size of a NXT filename (including file extension) which probably came from the 16 character limit of the NXT screen width pluse 3-character file extension. And this predated the implementation of the "Debug Stream" and the "sprintf" functions.

With the introduction of "sprintf" and "Debug Stream" then intent was to allow character constants of any length and to allow "sprintf" to work with character arrays of any length.

"sscanf" is implemented (and may even appear in undocumented form in 3.06). But it often breaks because of the imperfect pointer implementation that is planned for this summer.

The original intent of the "string" variable type was to introduce character manipulation in a safe fashion without pointers and without going crazy if the terminating NULL character did not exist. This is good for beginners but pretty irritating to people more accustomed to standard C's character manipulation functions. I've wanted to enhance the string type to allow a size declaraction on a per variable basis but this is low priority feature request.


Thu Mar 01, 2012 12:37 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.