Your SlideShare is downloading. ×

Ts 3742

283

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
283
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 2006 JavaOneSMConference | Session TS-3742 |Dancing While Gaming—Multitasking VMs (MVM)on Real DevicesJae Hyou Lee Yaniv ShaniSamsung Electronics Sun Microsystems, Inc.www.samsung.com www.sun.comTS-3742
  • 2. 2006 JavaOneSMConference | Session TS-3742 | 2GoalDeeper understanding of MultitaskingVM implementation on real devices
  • 3. 2006 JavaOneSMConference | Session TS-3742 | 3Project Highlights• A joint collaboration between SamsungElectronics and Sun Microsystems• MVM deployment is based on Sun’s JWC1.1.3• Deploying most of the MSA JSRs• Tested with hundreds of games andapplications from leading content providers
  • 4. 2006 JavaOneSMConference | Session TS-3742 | 4AgendaMVM overviewMVM in the configuration levelMVM in the profile level• The Foreground and Background state• Resource management• Multitasking safetyMIDlets in MVM environmentQ&A
  • 5. 2006 JavaOneSMConference | Session TS-3742 | 5AgendaMVM overviewMVM in the configuration levelMVM in the profile level• The Foreground and Background state• Resource management• Multitasking safetyMIDlets in MVM environmentQ&A
  • 6. 2006 JavaOneSMConference | Session TS-3742 | 6What Is MVM?• Running multiple applications simultaneously• Java is always on• Favorite applications instantly availableMP3 PlayingChattingGaming
  • 7. 2006 JavaOneSMConference | Session TS-3742 | 7MVM Conceptual ViewDevice H/WOperating SystemNative JVM TaskConfiguration LevelMVMResourceManagerApp.ManagerAMSJSR JSR JSRJSRProfile LevelMultitasking SafetyIsolation ModelDeployment GuidelinesLegacy ContentNew App StatesUser ExperienceResource Policies
  • 8. 2006 JavaOneSMConference | Session TS-3742 | 8AgendaMVM overviewMVM in the configuration levelMVM in the profile level• The Foreground and Background state• Resource management• Multitasking safetyMIDlets in MVM environmentQ&A
  • 9. 2006 JavaOneSMConference | Session TS-3742 | 9Isolates and TasksEach application runs in its own logical JavaVirtual Machine, called an Isolate.Within the JVM, each isolate is representedas a Task. A task consists of one more Javathread of execution.
  • 10. 2006 JavaOneSMConference | Session TS-3742 | 10More on Tasks…• All tasks execute in the same single OStask context• All tasks share:• Constant data structure• Runtime support functions• Each task encapsulates non-sharableprogram stateMVM
  • 11. 2006 JavaOneSMConference | Session TS-3742 | 11Implementation Details• Each task has a separate, private copy of the staticvariables of all the loaded Java classes• Static variables are only global to all threads withina particular taskStatic Variableclass A {public static int count;...}Task 1class A {public static int count;...}task 2MVM• Each task maintains aprivate copy of ‘count’• The Class representationis shared
  • 12. 2006 JavaOneSMConference | Session TS-3742 | 12Implementation DetailsSynchronizationclass A {public static synchronized int open();}• Synchronization has to be task private• Threads in one task cannot block threads in another taskTask 1 Task 2MVMA.open() A.open() A.open() A.open()Blocking Threads AcrossTasks Isn’t Allowed
  • 13. 2006 JavaOneSMConference | Session TS-3742 | 13Resource Management• The JVM is responsible for CPU time andmemory resources in order to ensure that alltasks get their “fair” share• Other resources, such as network bandwidthand communication ports are managed bythe profile layer
  • 14. 2006 JavaOneSMConference | Session TS-3742 | 14Resource Management—Scheduling• Tasks and thread arescheduled by the JVM• Fair scheduling algorithm isused for task scheduling inorder to prevent one taskfrom taking disproportionateCPU time• The ‘Isolate’ class offers aset of APIs to modify thepriority levels for each task`Task 2SchedulerMVMTask 1ActiveThreadMVM
  • 15. 2006 JavaOneSMConference | Session TS-3742 | 15Resource Management—Memory• All tasks allocations are conducted from thesame global heap region• The virtual machine has a bookkeepingmechanism that accounts for each task totalheap memory consumption• The JVM injects OutOfMemoryError as needed toinform tasks that heap space has become scarce
  • 16. 2006 JavaOneSMConference | Session TS-3742 | 16AgendaMVM overviewMVM in the configuration levelMVM in the profile level• The Foreground and Background state• Resource management• Multitasking safetyMIDlets in MVM environmentQ&A
  • 17. 2006 JavaOneSMConference | Session TS-3742 | 17New MIDlet State in MVM• An application is said to be in the Foreground when:• Its displayable controls the display• It handles event from the user input mechanism• Only one MIDlet can execute in the Foreground at a timeForeground MIDlet
  • 18. 2006 JavaOneSMConference | Session TS-3742 | 18New MIDlet State in MVMBackground MIDlet• An application is in the Background when:• Its displayable does not control the display• It does not handle the user inputs mechanism• Zero or more MIDlets can execute in the Backgroundat a time
  • 19. 2006 JavaOneSMConference | Session TS-3742 | 19The Application Manager• A resident MIDIet• Executed from power on• Lists the running applications• A fast way to switch betweenrunning MIDlets• Display backgroundMIDIets alerts
  • 20. 2006 JavaOneSMConference | Session TS-3742 | 20Switching a MIDlet to theBackground (1/3)• Upon a short ‘Hot’ key press the foreground MIDletwill be placed in the background and main devicemenu will be displayedShort ‘Hot’ Key PressShort ‘Hot’ Key
  • 21. 2006 JavaOneSMConference | Session TS-3742 | 21Switching a MIDlet to theBackground (2/3)• Upon a long ‘Hot’ key press the foreground MIDletwill be placed in the background and the ‘Applicationmanager’ dialog will be displayedLong ‘Hot’ KeyLong ‘Hot’ Key
  • 22. 2006 JavaOneSMConference | Session TS-3742 | 22Switching a MIDlet to theBackground (3/3)Invoking Display.setCurrent(null)• Upon calling setCurrent(null) the MIDlet will be placedin the background and the ‘idle’ screen of the devicewill be displayedDisplay.setCurrent(null)
  • 23. 2006 JavaOneSMConference | Session TS-3742 | 23Interrupting the User• Background MIDlet calls Display.setCurrent(alert)• Background MIDlet tries to access a protected APIand a security dialog is prompted• Noteworthy event occurred in the background• e.g., Incoming IM while playing a game
  • 24. 2006 JavaOneSMConference | Session TS-3742 | 24DEMOUser Experience Demonstration
  • 25. 2006 JavaOneSMConference | Session TS-3742 | 25AgendaMVM overviewMVM in the configuration levelMVM in the profile level• The Foreground and Background state• Resource management• Multitasking safetyMIDlets in MVM environmentQ&A
  • 26. 2006 JavaOneSMConference | Session TS-3742 | 26Managing Resources• In a single-tasking environment, the MIDlethas access to all of the available resources• In a multitasking environment, MIDlets haveto compete for available resources
  • 27. 2006 JavaOneSMConference | Session TS-3742 | 27Managing Resources• Mechanisms• Reservation• Quota• Revocation• Policies• Fixed partition• Open for competition• Special cases
  • 28. 2006 JavaOneSMConference | Session TS-3742 | 28Resource Management Mechanisms• A reservation mechanism sets aside acertain amount of a resource for a MIDletand keeps it available for that MIDlet andthat MIDlet aloneReservation
  • 29. 2006 JavaOneSMConference | Session TS-3742 | 29Resource Management Mechanisms• A quota mechanism permits a MIDlet to allocateup to a certain amount of a resource; if theMIDlet attempts to allocate more resources thanits quota, the attempt fails, even if resources areactually available on the systemQuota
  • 30. 2006 JavaOneSMConference | Session TS-3742 | 30Resource Management Mechanisms• The system can revoke a resource from aMIDlet and give it to another MIDlet• Resource revocation examples:• CPU cycles• Display access• Audio playback• Resource revocation doesn’t always have adramatic effect on the MIDlet’s executionRevocation
  • 31. 2006 JavaOneSMConference | Session TS-3742 | 31Resource Management Policies• Initial amount of resources are reservedbefore MIDlet launch• Resource availability validation duringMIDlet’s startup• Ensure consistent MIDlet behaviorFixed Partition
  • 32. 2006 JavaOneSMConference | Session TS-3742 | 32Resource Management Policies• No reservation• Resource are acquired and reclaimed at runtime• May lead to unpredictable behaviorOpen for Competition
  • 33. 2006 JavaOneSMConference | Session TS-3742 | 33Special ResourceManagement Policies• Only the Foreground can access the LCDdisplay and receive key inputs events• The current displayable of a BackgroundMIDlet is still updatedNote: vibrate() ,flashBacklight() and toneplaying aren’t honored when invoked froma Background MIDletLCD Display
  • 34. 2006 JavaOneSMConference | Session TS-3742 | 34Sound (1/2)Special ResourceManagement Policies• Foreground MIDlets are assigned physical player thatcan access the audio device resource• Background MIDlets are assigned a logical player thatonly maintains the audio state• Upon foreground switch the player state is changedautomaticallyLogical PlayerPhysical Player1Logical PlayerPhysical Player2ForegroundSwitch
  • 35. 2006 JavaOneSMConference | Session TS-3742 | 35Special ResourceManagement Policies• Unique JAD file property to lock audio resources• Allows a background MIDlet to be audible• Useful for media players (e.g., the MP3 player,radio, etc.)Sound (2/2)1Logical PlayerPhysical Player2Logical PlayerPhysical Player1ForegroundSwitch
  • 36. 2006 JavaOneSMConference | Session TS-3742 | 36A Full Resource Policy MatrixFixed Open SpecialMemory X XCPU X XFile Descriptor X XSocket X XDisplay XSound X XBluetooth XLocation XPIM X
  • 37. 2006 JavaOneSMConference | Session TS-3742 | 37Guidelines for ResourcePolicy Selection• Resource policy definition relies on theunderlying platform capabilities andrequirements• Fixed partition policy should be used forfundamental resources that are required bythe majority of the applications (e.g., memory,file, socket)• Open policy should be used resources that areused by specific MIDlets and have limitedavailability (e.g., Bluetooth, location)• Display and sound requires special handling
  • 38. 2006 JavaOneSMConference | Session TS-3742 | 38DEMOResource Policy Demonstration
  • 39. 2006 JavaOneSMConference | Session TS-3742 | 39AgendaMVM overviewMVM in the configuration levelMVM in the profile level• The Foreground and Background state• Resource management• Multitasking safetyMIDlets in MVM environmentQ&A
  • 40. 2006 JavaOneSMConference | Session TS-3742 | 40Multitasking Safety• The native JVM task can run native code forany task, hence the code must be madeaware of the task on whose behalf it is beingcalled and possibly allocating resources• When the task context is established, thecode is considered multitasking safe• Sun’s JWC software is multitasking safe
  • 41. 2006 JavaOneSMConference | Session TS-3742 | 41Multitasking SafetyImplementation Guidelines• In some cases a deployment of a profile to MVMenvironment requires additional development in orderthat the profile will execute properlyForegroundSwitchBlocking Threads AcrossTasks Isn’t Allowed
  • 42. 2006 JavaOneSMConference | Session TS-3742 | 42Multitasking Safety• At Java level, each task has a separate, privatecopy of the static variables of all the loaded Javaclasses• This is handled internally by the MVM• Native code often has global data• Native data is shared across all tasks!• Global native data needs to be replicated foreach task• Held as a field of a Java object• Proper handling for singleton depends on whetherit is meant be used on a per-task basis (the defaultbehavior for MVM), or by the entire systemStatic and Global Variable
  • 43. 2006 JavaOneSMConference | Session TS-3742 | 43AgendaMVM overviewMVM in the configuration levelMVM in the profile level• The Foreground and Background state• Resource management• Multitasking safetyMIDlets in MVM environmentQ&A
  • 44. 2006 JavaOneSMConference | Session TS-3742 | 44MIDlet Guidelines• MIDlets developed on top of ‘Canvas’ class willreceive the following notifications:• Canvas.hideNotify(): When switching to background• Canvas.showNotify(): When returning to foreground• MIDP2.0 spec. doesn’t offer APIs for MIDlet thatdoesn’t use the ‘Canvas’ class facilitiesMIDlet State Detection
  • 45. 2006 JavaOneSMConference | Session TS-3742 | 45MIDlet Guidelines• Switching to background does not pause aMIDlet by default• Legacy content handling• Some MIDlets (e.g., legacy games) will not runcorrectly in the background• A new JADfile property can request that the MIDletbe paused when switched to backgroundIn the Background, Am I Paused?
  • 46. 2006 JavaOneSMConference | Session TS-3742 | 46MIDlet State Detection• Most of the games should be suspended inbackground• Player may be inadvertently killed• Free up resource that aren’t in use• No need to continue painting when nobody seesthe results• Make sure to attract the users attention whensomething interesting happens in thebackgroundHow to Behave While Executing in Background?
  • 47. 2006 JavaOneSMConference | Session TS-3742 | 47MIDlet Guidelines• Return resources when you are done withthem, don’t wait for destroyApp()• Expect and detect failures in resourceacquisition• Help the users to overcome resourceacquisition failure• Expect to see new JAD file properties forresource policy indication (heap size, specialsound policy, etc.)Resource Awareness
  • 48. 2006 JavaOneSMConference | Session TS-3742 | 48Boot-time MIDlets• Launch in the background at boot time• Bring to foreground upon arrival ofincoming event• Examples:• MMS, SMS, IM, Mail clients• Stock, weather, news
  • 49. 2006 JavaOneSMConference | Session TS-3742 | 49Summary• MVM in the configuration level:• Isolation Model• JVM executes in a single native task context• MVM in the profile level• Foreground and Background state• Resource management and policy• User experience• Multitasking safety• MIDlets in MVM environment
  • 50. 2006 JavaOneSMConference | Session TS-3742 | 50AgendaMVM overviewMVM in the configuration levelMVM in the profile level• The Foreground and Background state• Resource management• Multitasking safetyMIDlets in MVM environmentQ&A
  • 51. 2006 JavaOneSMConference | Session TS-3742 | 51Q&A
  • 52. 2006 JavaOneSMConference | Session TS-3742 |Dancing While Gaming—Multitasking VMs (MVM)on Real DevicesJae Hyou Lee Yaniv ShaniSamsung Electronics Sun Microsystems, Inc.www.samsung.com www.sun.comTS-3742

×