I learnt something new about bytecode optimization today. In languages like C and C++, if you’re really concerned about efficiency, you can drop into assembly mode and write specific assembly code instead of relying on the compiler to convert your C/C++ code into assembly (compilers can optimize, but not as well as humans in all cases).
I saw a question on Stackoverflow today that talked about the getfield opcode in the context of the trim() method in the String class. In the trim() method, you have the following comments:
int off = offset; /* avoid getfield opcode */
char[] val = value; /* avoid getfield opcode */
The author of the question wanted to know what these comments mean. This question seemed pretty interesting to me and so I went and did some research. I found out that getfield is an operation that lets you get access to the member variable/field of a class. This operation is fairly expensive as it involves indexing into the runtime constant pool. Performing this operation a few times does not really incur a performance hit. It is when you perform the operation multiple times, that performance becomes an issue. You can see this from the next few lines of code:
while ((st < len) && (val[off + st] <= ' ')) {
st++;
}
while ((st < len) && (val[off + len - 1] <= ' ')) {
len--;
}
Now if the author of the trim() method hadn’t assigned offset and value to local variables, a getfield operation would be performed every time the loop-condition is tested. This is obviously inefficient. Therefore, the author assigned the the values of offset and val into the local variables off and val. So now, instead of getfield you have iload (for off anyway), which performs much faster.
Popularity: 5% [?]
January 21, 2011
Posted by
vivin |
Assembly, Computers, Java | assembly, bytecode, bytecode optimization, getfield, iload, java, optimization |
Leave a Comment
As some of you may already be aware, it appears that the G2 has some sort of “magic restore” (it’s not a rootkit) function that causes all changes to /system to be reverted. This means that you cannot remove any bundled bloatware. Even more troubling, it looks like the phone will perform the restore while it is running (i.e, you don’t need a reset). I haven’t turned on my G2, so this is what I’ve heard from people at XDA Developers. You can get temporary root on the devices, but after a little while (some people say minutes, others say hours; experiences seem to vary) root is lost. So it is possible that something is performing the restore while the phone is running.
Helpful folks on XDA Developers have posted the datasheet to the eMMC and another kind soul (damnoregonian) was able to get the value of the CSD register (the register that seems to control the behavior of the MMC): d00f00320f5903fffffffdff924040c8.
WP_GRP_SIZE[36:32] and WP_GRP_ENABLE[31:31] seem to be the bits that control the write-protect (per the datasheet). Currently these seem to be set to the default values per the data sheet (11111b and 1b). Clearing the bits should (theoretically) turn off the write protection. The value to do that would be d00f00320f5903fffffffde0124040c8. The CSD node is R/O and so you cannot echo to it directly. The only way to do it would be to write a kernel module/driver that writes to the register. Apparently the kernel exports a function called mmc_send_csd, and so one should be able to write to this register.
I’m tempted to write a kernel module that does just that. But since working at Intel I haven’t written any kernel drivers. Also while I did write drivers at Intel, I pretty much made modifications to what others before me had written, and so I never wrote one from scratch. I’m going to see if I can start on something this weekend… wish I was still in college… I had a lot more time then!
If this works (and that’s a big if), there’s still the issue of restores being done while the phone is in operation. That could cause a lot of inconsistency. So this might be a partial solution.
Either way, I’m sure someone will come up with a way to root the phone. But if there’s nothing by next Friday, I’m going to return the phone.
UPDATE
Someone posted updated specs. It looks like those bits are read-only. Bummer. Also, this from T-Mobile’s website:
Bellevue, Wash. — Oct. 7, 2010
As pioneers in Android-powered mobile devices, T-Mobile and HTC strive to support innovation. The T-Mobile G2 is a powerful and highly customizable Android-powered smartphone, which customers can personalize and make their own, from the look of their home screen to adding their favorite applications and more.
The HTC software implementation on the G2 stores some components in read-only memory as a security measure to prevent key operating system software from becoming corrupted and rendering the device inoperable. There is a small subset of highly technical users who may want to modify and re-engineer their devices at the code level, known as “rooting,” but a side effect of HTC’s security measure is that these modifications are temporary and cannot be saved to permanent memory. As a result the original code is restored.
Well, T-Mobile. How about you provide us technical users a way to root our devices? What you’re doing is stupid. You’re going against everything Android stands for. If I can’t root it, I think I will return my phone and get a Vibrant instead. I would have expected this from Apple or Verizon. But not from you. Very disappointing.
Popularity: unranked [?]
October 7, 2010
Posted by
vivin |
Android, Assembly, C, Computers, Hardware, Nerdy Stuff, Programming and Development, Technology | drivers, emmc, g2, kernel drivers, kernel modules, linux, mmc, modules, root, rooting, xda developers |
Leave a Comment
Today was Dr. Pheanis’ last day as a professor. We were his very last class. He said he would remember us the most because we were his last class. I think it is very fitting that the CSE 521 class would be his last. We are essentially (in his view – I am not just saying this), his best students… the “creme de la creme” as he put it. There are very few students that he invites to take CSE 521. CSE 521 is a hard class and he invites you to take it only if he thinks you are smart enough to take it. I am glad he thought I was smart enough to take it. I like to think that we represent his success as a professor.
ASU is losing an excellent professor… not that anyone in the management cares because they have their own f**king agendas. I really wonder what will become of the embedded systems department once Dr. Pheanis leaves.
I really am glad to have been taught by him. It really is an honour.
Popularity: 1% [?]
May 4, 2004
Posted by
vivin |
Assembly, Life, Programming and Development, School | asu, cse 521, dr. pheanis, inspiration, professors, teachers |
1 Comment
Ah finally! Someone made use of the Comments! I feel so special! Thanks Ed! Yeah and life sucks.
Radix Sort is an amazing algorithm. Too bad my teammate and I failed our first demo because we made the absolutely dumb mistake of not distinguishing between a BYTE and a LONGWORD. Yeah big difference.
Anyway, I thought this was cute:
Adam and Eve had an ideal marriage. He didn’t have to hear about all the men she could have married, and she didn’t have to hear about the way his mother cooked. (Kimberley Broyles)
Popularity: 1% [?]
February 24, 2004
Posted by
vivin |
Assembly, Life, Love and Marriage, Musings, Ramblings, and Inanities, Programming and Development, School | asu, comments, cse 521, my website, radix sort |
1 Comment
I don’t want to leave… It’s back to CSE 421… I can’t believe Thanksgiving is over… I JUST GOT HERE!!! Crap…
Popularity: 1% [?]
December 1, 2002
Posted by
vivin |
Assembly, Family and Friends, Life, Programming and Development, School | cse421, thanksgiving |
Leave a Comment
Just got a call from Intel today. Found out that I’ve been selected for an interview there. I’ll be doing the interview… and if I get both (!) then I’ll have to decide which one I want. It feels good to know that I’ve been selected…
Lab 9 is pretty interesting! It’s gonna be hella hard… but… interesting!
Popularity: 1% [?]
November 19, 2002
Posted by
vivin |
Assembly, Life, Programming and Development, School, Work | cse421, intel, internship |
Leave a Comment
My lab looks like it works. I think this has been completely unfair. I’ve been working on it for a week… and it’s as if I just started… Sometimes you get it, sometimes you don’t…
Popularity: 1% [?]
November 13, 2002
Posted by
vivin |
Assembly, Life, Programming and Development, School | cse421 |
Leave a Comment
I had an interview with Motorola on Friday. It went alright I think. I hope I get the job. It’s for an internship in spring. They asked me if I’d be interested in working through summer and fall, and I said yes. They were pretty impressed with my resume, which reminds me… I should update the HTML version. Well, anyway… There were four people interviewing me. Initially I thought it was intimidating. But they started off really well by asking me about stuff I had done… So I felt comfortable right away. They were looking for team experience and C code and Linux. I’ve done all that. One of the interviewers asked me what I used to do my code… what sort of GUI. I said “I use nothing but vi and the commandline”. He’s like “You’re my man! I’ve been waiting for someone to say that! No one else uses the commandline!”. So that was promising. I’ll be happy if I land this position.
I really like FreeBSD. I’ve broken my system a lot of times, but I learn something new each time. Right now it’s pretty neat. I’m having trouble playing DivX stuff and mplayer doesn’t work. I’m still new at all of this, so there’s a HUGE learning curve. Maintaining your own UNIX box is whole lot different from using a UNIX account. The latter helps, the former is a different animal. I like it though.
The assembly program that I’m currently testing and debugging is the most inefficient one to date. I’m too embarassed to say what the size is. Well… as long as it works. I’m insane and I’m planning to take CSE 521 next semester. For the final project, you write an OS for the M68000 microprocessor. I think that’s just kick ass. What a sad life I have…
Popularity: 1% [?]
November 9, 2002
Posted by
vivin |
Assembly, Life, Programming and Development, School, Work | assembly programming, cse421, cse521, freebsd, internship, interview, m68000, m68k, motorola, os, unix |
Leave a Comment
Comments, Radix Sort, Adam and Eve
Ah finally! Someone made use of the Comments! I feel so special! Thanks Ed! Yeah and life sucks.
Radix Sort is an amazing algorithm. Too bad my teammate and I failed our first demo because we made the absolutely dumb mistake of not distinguishing between a BYTE and a LONGWORD. Yeah big difference.
Anyway, I thought this was cute:
Adam and Eve had an ideal marriage. He didn’t have to hear about all the men she could have married, and she didn’t have to hear about the way his mother cooked. (Kimberley Broyles)
Popularity: 1% [?]
February 24, 2004 Posted by vivin | Assembly, Life, Love and Marriage, Musings, Ramblings, and Inanities, Programming and Development, School | asu, comments, cse 521, my website, radix sort | 1 Comment