There are many different Jailbreaking options available for the Apple iPhone currently online which would allow you to Jailbreak 3GS on iOS4, Jailbreak 3GS, Jailbreak iPhone 3, iPhone 3.1.2 using different tools like Redsn0w, Ultrasn0w, Pwnagetool etc all of which are useful for different version of Apple devices and different version of Operating Systems installed on them. Its always advisable that before you plan to upgrade your device to the newer version, you should check out if there is a jailbreaking tool available for the same or else you would end up with a bricked device. Currently there are huge number of iPhone owners who have a iPhone with New Bootrom for which the jailbreaking tool is yet to be announced. This is the very reason its also important to Find Bootrom Version of your device to find the respective unlocking files.
Currently if you have the SHSH Blobs stored from the previous 3.1.2 version on your computer then there are chances that after completing a 4 hours lengthy and geeky procedure you can perform a Tethered Jailbreak which means that after the phone is jail-broken, whenever you reboot it you will have to connect it to your computer to get it back to the normal stage. Another advice is not to upgrade and also not to go for this kind of methods because that would increase your problem rather than giving you a solution for the same.
The PwnageTool V 4.01 tool allows you to Jailbreak iPhone 3GS, 3G, iPod Touch 2G. If you try to jailbreak the wrong device then you will get stuck at ‘connect to iTunes for activation’ or else when you try to use the tools like Sn0wbreeze which would create custom .ipsw files and also install the Cydia installer in your device. You also need to make sure that the device is in DFU Mode or Restore mode to finally restore the custom .ipsw file on to your device.
In case the device is struck in the Restore Mode Loop, you will have to download tools like ireb which would then forcibly make the device to come back to the normal mode. Many iPhone users get a error of iTunes 1600 1601 1602 1603 1604 iPhone Restore Error which the Apple notes that you need to reinstall iTunes to the higher version or else use another computer, but the best possible solution for this is to downgrade the iTunes software and try the whole process again by getting the device into DFU Mode.
For the iPhone 3G or iPhone 3GS devices with New Bootrom iOS4 or 3.1.3 OS there is soon coming up based on spirit which would make all this process a very simple one. Lets wait and hope for the best.