Japanese police have extraordinary powers compared with their Western counterparts: they have the right to detain a suspect without charging them for up to 48 hours. If the police can convince a judge of sufficient cause, they can detain you for a further 10 days (which can be extended for an additional 10 days). Bail is rarely granted.
You have the right to remain silent and the right to a lawyer. Note that police may begin questioning before a lawyer is present. If you do find yourself in police custody, you should first insist on speaking to your embassy and refuse to cooperate in any way until you are allowed to make such a call. Insist that a tsuyakusha (interpreter) be summoned (this is best, even if you can speak Japanese).
Japan takes a particularly hard-line approach to narcotics possession, with long sentences and fines even for first-time offenders.
Note that it is a legal requirement to have your passport (or, if you are staying longer than 90 days, your resident card) on you at all times. Though checks are not common, if you are stopped by police and caught without it, you could be hauled off to a police station to wait until someone fetches it for you.